Software Design Patterns Flashcards
1
Q
Explain the Strategy Pattern and when to use it
A
The strategy Pattern is an implementation of the Compositional Reuse Principle. (composition over inheritence)
The Strategy Pattern defines a family of algorithms,
encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
The pattern: Context.strategy(strategy1) //strategy2, or 3
2
Q
When to use the Strategy Pattern
A
When you have a part of your Class that’s subject to change frequently or perhaps you have many related subclasses which only differ in behavior it’s often a good time to consider using a Strategy pattern.