디자인 패턴 구성
Strategy pattern 예시
Name: Strategy pattern
Intent: Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
Motivation: Different algorithms are implemented directly(hard-wired), it is impossible to add/change algorithms independently from the context. Wants more flexibility and want to exchange algorithm at run time
Structure:
Consequence:
Pros (+)
1) Avoids compile-time implementation dependencies.
2) rovides a flexible alternative to subclassing.
3) Avoids conditional statements for switching between algorithms.
Cons (–)
1) Can make the common Strategy interface complex.
2) Requires that clients understand how strategies differ.
3) Introduces an additional level of indirection.