Chapter 1. Introduction to Design Pattern
Design Principle
- Identify the aspects of your application that vary and separate them from what stays the same.
- Program to an interface (java), not an implementation. (polymorphism)
- Favour composition over inheritance. Composition allows to change behaviour at runtime.
Strategy Pattern
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.
Advantages
- Encapsulate what varies. Make the program extensible and maintainable.
- Define a family of algorithms and allow runtime modification.