Dev Notes – Design Patterns
- Abstract Factory
- Factory Method (Virtual Constructor)
- Adapter (Wrapper)
- Strategy (Policy)
- Template Method
- Chain of Responsibility
Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
Separate the construction of a complex object from its representation so that the same construction process can create different representations.
Virtual Constructor. Methods which create an instance of another class.
Cloning an object by reducing the cost of creation.
Ensure a class allows only one object to be created, providing a single point of access to it.
Convert the interface of a class into another interface clients expect.
Allows behaviour to be added to an existing object dynamically.
Provide a surrogate or place-holder for another object to control access to it.
Change the way a difficult interface works by presenting a more simpler interface, easier to work with.
Use sharing to support large numbers of fine-grained objects efficiently.
HAS-A. Decouple an abstraction from its implementation so that each may vary independently.
Compose objects into tree structures. Treat branches and leafs the same.
Mediator promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.
Classes whose functionality doesn’t agree with the extended class functionality.
Define the skeleton of an algorithm in a method, deferring some steps to sub-classes.
Chain of Responsibility
Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request.
Allows us to de-couple an object making a request from the object that receives the request and performs the action, by means of a “middle-man” object.
Used to store the state of an object to return it that state later. E.g Undo.
Used for definition of a representation for given language grammar along with an interpreter that uses the representation to interpret sentences in the language.
Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
Define a one-to-many dependency between objects so that when one object changes its state, all its dependants are notified and updated automatically.
Allow an object to alter its behaviour when it’s internal sate changes. The object will appear to change its class.
Lets you define a new operation without changing the classes of the elements on which it operates. Double dispatch.