Principles

  • Encapsulate that varies. Identify the aspect of your application that vary and separate them from what stays the same.
  • Program to an interface(supertype), not an implementation.
  • Favour composition over inheritence. HAS-A can be better than IS-A. Eg. Duck has a FlyingBehaviour

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. Enables the exact behaviour of a system to be selected at either run-time(dynamic) or compile-time(static).

strategy_pattern

Reference