Strategy Pattern
The Strategy Pattern defines a family of algorithms, encapsulates each one, and them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
Design Principle
- Favor composition over inheritance.
- Program to an interface, not an implementation.
- Identify the aspects of your application that vary in other words, encapsulate what varies and separate them from what stays the same.
Example:
Latest Source Code:
Github: MiniDuckSimulator.java
Output:
I'm flying. Quack I can't fly. I'm flying with a rocket!