The best way to retain design patterns is to memorize, understand how they work and finally identify places where they are applicable while designing applications.
CHANGE is the One Constant in Software Development.
Strategy lets the algorithm vary independently from clients that use it.
- Take the parts that vary and encapsulate them, so that later you can alter or extend the parts that vary without affecting those that don’t.
- Depending only the interface allows for loose coupling of inter dependent classes
- It prevents a class from getting locked with a concrete implementation, instead it will be relying on an interface
- There are three types of relationships between classes: IS-A (inheritance), HAS-A (composition), Implements
- Using compostion allows for more flexibilty by encapsulating a family of algorithms into logical classes
“Knowing basic OO concepts doesn't automatically make you a good OO designer”
It defines a one-to-many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically.
Allows us to build flexible OO systems that minimize interdependency and allow for extensibility
example
It involves a set of decorator classes that are used to wrap concrete components.
The Factory Method Pattern defines an interface for creating an object, but lets subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.