Design Patterns are reusable solutions to the problems software architecture faces regularly. Patterns must explain why the solution provided is the best amongst the equals.
Most popular 23 Gang of Four patterns are considered to be the base of all patterns. These patterns are categorised in three groups:
1. Creational Patterns: These patterns help create object for you, hence giving flexibility in making decision for a given case.
a. Factory method: Creates an instance without specifying the exact class. It lets defer instantiation to subclasses.
b. Abstract Factory: It helps create several families of classes. Provide an interface for creating families of related classes without specifying there exact class.
c. Builder : It help separate complex construction from representation and hence allowing same construction process to create multiple representation.
d. Prototype: It helps create objects by cloning existing objects.
e. Singleton : Restricts object creation to only one single object.
f. Object Pool: Avoid expensive creation and deletion of resources by recycling objects that are no longer in use.
g. : Multiton : Its an extension of singleton class objects by keeping key value pairs.
2. Structural Patterns: These patterns help structure object composition using inheritance. By achieving different object composition they attain new functionality.
a. Adapter: Matches interfaces of incompatible classes by wrapping up its own interface around.
b. Bridge: It allows decoupling of interface with its implementation, so that two can vary independently.
c. Composite: Composes one or more similar objects to represent part-whole hierarchies. It lets client treat individual objects of the whole composition uniformly.
d. Decorator: It dynamically adds features on an existing object. It provides a flexible alternative to sub-classing for extending functionality.
e. Facade: Provides a simple interface for a large subsystem.
f. Flyweight: It reduces the cost of creating and manipulating a large number of similar objects.
g. Proxy: Provides a surrogate for another object to control access, reduce cost, and reduce complexity.
h. Front Controller : It provides centralized entry point for handling requests. Its mostly for Web Applications.
i. Module : Group of related classes, methods into single conceptual entity.
3. Behavioral Patterns: These patterns resolve communication issues with objects.
a. Chain of Responsibility: Delegates the command to chain of processing objects and hence avoid coupling the sender of request to receiver.
b. Command: Creates request that encapsulate actions and parameters hence let us do undo-able operations.
c. Interpreter: It lets us define grammar of specialised language.
d. Iterator: Sequentially access elements of an object without exposing its internal representation.
e. Mediator: Promotes loose coupling by keeping objects from referring to each other explicitly, and it lets you vary their interaction independently.
f. Memento : Allows undo operation by capturing and restoring its original state.
g. Observer: Publish/Subscribe pattern that allows various objects to see an event.
h. State : It allows changing of behaviour of an object when its internal state changes.
i. Strategy: It allows one of the family of algorithm to be selected in the runtime.
j. Template: Defines skeleton of the algorithm as base classes, letting subclass define its concrete behaviour
k. Visitor: It lets you define new operation without changing the classes of the elements. It separates an algorithm from its object structure by moving the hierarchy of methods into one object
L. BlackBoard: Generalized observer, which allows various readers & writes, distributes information system wide.
M. Null Object: Provides a surrogate for another object that shares the same interface but does nothing.
O. Servant : It separates out common functionality from a group of classes. It implements some functionality which is common to group of classes and is not defined in them.
P. Specification Pattern: Outlines business rule that is combinable with other business rule. A unit of business logic inherits its functionality from abstract aggregate composite specification.