Design pattern describes solutions to a problem which arises while developing software for a specific condition. Design patterns are basically independent of any programming language. Lot of guys do the mistake of thinking it as an algorithm but its a common way to solve a generic problem which can be simple or complex.
Basically there are three different categories of design patterns depending on the problem they address:
- Creational Patterns
- Structural Patterns
- Behavioural Patterns
Creational Patterns:
These design patterns solves the given problem by means of object creation mechanism. Normal way of object oriented solution to solve a problem sometimes create design problems and increasing complexity of the software. Thus, a set of design patterns are there to handle such kind of issues. Examples of this category of design patterns are as follows:
- Factory Method – This design pattern is used to create an instance from the family of various derived classes.
- Abstract Factory Method – This design pattern is used to create an instance from the several family of various derived classes.
- Builder Method – This design pattern is used to separate construction and representation of an object to create different objects via same construction process.
- Prototype Method – This design pattern is used clone mechanism to create a new object from a fully initialized object to minimize cost creation of new object.
- Singleton Method – This design pattern is used to create one and only one object of a class of global context to provide co-ordination between various modules of a software.
Structural Patterns:
These design patterns solves the given problem by means of class and object composition to provide required functionality. Examples of this category of design patterns are as follows:
- Adapter – This design pattern is used to adapt the interface of a class into another interface which other module expects.
- Bridge – This design pattern is used to separate out the interface from its implementation logic to provide flexibility.
- Composite – This design pattern is used to create a tree structure of objects to provide hierarchies in the software.
- Decorator – This design pattern is used to provide additional functionality to an objects dynamically.
- Facade – This design pattern is used to hide the complexities of the system by providing a simple interface to other module of the system.
- Flyweight – This design pattern is used to share properties of objects to reduce maintenance cost of objects.
- Proxy – This design pattern is used to create an object for another object to hide the complexities and reduce maintenance cost of the object.
Behavioural Patterns:
These design patterns solves the given problem by means of communication between different class objects. Examples of this category of design patterns are as follows:
- Chain of Responsibility – This design pattern is used to to handle passing of information from a chain of objects until one of them handles it.
- Command – This design pattern is used to encapsulate a request as an object.
- Interpreter – This design pattern is used to provide a way to include grammar of a language to interpret sentences in the language.
- Iterator – This design pattern is used to iterate through a similar collection of objects.
- Mediator – This design pattern is used to encapsulate way of interaction between objects to simplify communication between classes.
- Memento – This design pattern is used to capture an object to expose object’s internal state without violating encapsulation.
- Observer – This design pattern is used to handle notification to multiple objects due to one object modification.
- State – This design pattern is used to change the functionality of an object whenever its state changes.
- Visitor – This design pattern is used to provide a way to define a new functionality to a class object without changing its structure.
- Strategy – This design pattern is used to encapsulate various algorithm inside class to allowing the change of algorithm randomly.