Strategy Pattern - PowerPoint PPT Presentation

1 / 7
About This Presentation
Title:

Strategy Pattern

Description:

Strategy Pattern. Parul Patel. Josh Goodrich. Justin Plotkin. Jonas Wei. Purpose of Strategy Pattern: ... Strategy lets the alogorithm vary independantly from ... – PowerPoint PPT presentation

Number of Views:23
Avg rating:3.0/5.0
Slides: 8
Provided by: pnpa
Category:

less

Transcript and Presenter's Notes

Title: Strategy Pattern


1
Strategy Pattern
  • Parul Patel
  • Josh Goodrich
  • Justin Plotkin
  • Jonas Wei

2
Purpose of Strategy Pattern
  • Encapsulate different algorithms
  • Strategy lets the alogorithm vary independantly
    from the clients that use it.
  • The Strategy pattern defines an abstract policy
    for performing an algorithm At the same time it
    provides multiple mechanisms that can comply with
    that policy, thus letting mechanism vary
    independently from the policy required.

3
Use When
  • You have many related classed that differ only in
    their behavior.
  • You need different variants of an algorithm.
  • An algorithm uses data that clients shouldn't
    know about.
  • It helps to avoid exposing complex,
    algorithm-specific data structures.
  • When you have several conditional statements in
    the program.

4
Strategy Pattern Example 1
5
Strategy Pattern Example 2
6
Benefits
  • Families of related algorithms
  • An alternative to subclassing
  • Easier to vary algorithm
  • Removes hard-wiring
  • Strategies eliminate conditional statements.

7
Drawbacks
  • The application must be aware of all the
    strategies to select the right one for the right
    situation.
  • Increased number of object
  • Context and the Strategy classes normally
    communicate through the interface
Write a Comment
User Comments (0)
About PowerShow.com