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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly