Design Patterns 

PART 2

Nirdosh, Milan

Strategy Pattern

Intent:

 

"Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm very independently from clients use it "

 

Also known as Policy.

Strategy without Pattern:

Open Close Principal : Software Entities should be open for extension, but closed for modification

Non Usable: Strategy is not usable by any other context

Strategy with Pattern:

Applicability

  • Many related classes differ only in their behavior
  • You need a different variant of an algorithm
  • To avoid exposing complex, algorithm-specific structures
  • Avoid class with many if -else statements

Consequences

  • Families of related algorithms
  • An alternative to Subclassing
  • Eliminates conditional statements
  • Client must be aware of strategies

 

 

Challenge ...

Hands - On ...

Made with Slides.com