Intention:
Purpose of the article is to describe and remember GOF patterns in a quick way by having a short description and diagram.This page do not provide entire description and selection principles or use cases for each patern, for more details please refer to the following books:
- Head First Design Patterns by Eric Freeman, Elisabeth Robson, Bert Bates, Kathy Sierra.
- Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides, Grady Booch.
Description:
Christopher Alexander says:"Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice" [1]
Pasterns are split in 3 main groups:
Group | Pattern | Description |
Structural | Adapter | Allows the interface of an existing class to be used from another interface. |
Bridge | Allows decoupling abstraction from implementation so that the two can vary independently. | |
Composite | Responsible to compose objects structure into tree and enable to treat them in the same way as a single object. | |
Decorator | Allows behaviour to be added to an individual object without affecting the behaviour of other objects from the same class. | |
Facade | Provides a simplified interface to a larger body of code or subsystem. | |
Flyweight | Allows to minimize memory used by sharing as much data as possible with other similar objects storage costs of objects. | |
Proxy | A wrapper or agent object that is being called by the client to access the real serving object behind the scenes. | |
Creational | Abstract Factory | Provides a way to encapsulate a group of individual families without specifying their concrete classes. |
Builder | Create composite object and describes the way how the object gets created. | |
Factory Method | Creating objects without having to specify the exact class of the object that will be created. | |
Prototype | Describes type of objects to be created which is determined by a prototypical instance. | |
Singleton | Restricted creation of instances and promote sole instance per system. | |
Behavioral | Chain of Responsibility | Each processing object contains algorithms that defines the types of command objects that it handles. |
Command | An object is used to encapsulate all information needed to perform an action or trigger an event at a later time. | |
Interpreter | Specifies how to evaluate grammar and interpretation of a language. | |
Iterator | Used to describe the way how to traverse a container and access the container of the elements. | |
Mediator | Defines an object that encapsulates how and which objects interact with each other. | |
Memento | Provides the ability to restore an object to its previous state. | |
Observer | Subject maintains a list of its dependencies, and notifies them automatically of any state changes. | |
State | Encapsulate different behaviour for the same object based on its internal state. | |
Strategy | Enables an algorithm's behaviour to be selected at a runtime. | |
Template Method | Defines the program skeleton of an algorithm in a method. | |
Visitor | Allows separate an algorithm from an object structure on which it operates. |
Structural Patterns:
Structural patterns is responsible for composition of objects might be named as well entities builder, those pasterns is dealing with data structures.Adapter
Bridge
Composite
Decorator
Facade
Flyweight
Proxy
Example of Proxy pattern available on github: https://github.com/ecararus/proxy
Abstract Factory
Chain of Responsibility
Conclusion:
The scope of design patterns is to provide an optimal designed solution for a specific range of problem, as well pattens should serves as referral for every software developer and help in communication with others.
[1] Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides, Grady Booch - p12.
Creational patterns:
Creational patterns responsible for ways of object creation.Abstract Factory
Builder
Behavioral Patterns:
Behavioral patterns responsible for ways in which classes or objects interact and separation of concerns.Chain of Responsibility
Visitor
Conclusion:
The scope of design patterns is to provide an optimal designed solution for a specific range of problem, as well pattens should serves as referral for every software developer and help in communication with others.
[1] Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides, Grady Booch - p12.