A design pattern is a reusable solution to a recurring problem in software design.
Benefits of using Design Patterns
- Best Practices – Design patterns represent the best practices used by experienced software developers.
- Language Independent – Design Patterns are language neutral and so can be applied to any language that supports object-orientation.
- Reusable : Design Patterns provides solutions that can be reused to solve similar kind of problem.
- Flexible: Design Patterns provides structure to solve a generalized problem which can be modified to suit the specific need.
GOF Design Pattern Catogeries
There are 23 Gang of Four (GoF) design patterns, that are generally considered the foundation for all other patterns. These are categorized under three groups:
1. Creational Design Patterns
These design patterns provide a way to create objects while hiding the creation logic, rather than instantiating objects directly using new operator. This helps in deciding which objects need to be created for a given use case.
|Abstract Factory||Creates an instance of several families of classes|
|Builder||Separates object construction from its representation|
|Factory Method||Creates an instance of several derived classes|
|Prototype||A fully initialized instance to be copied or cloned|
|Singleton||A class of which only a single instance can exist|
2. Structural Design Pattern
These design patterns concern class and object composition to form a larger structure. Inheritance is used to compose interfaces and define ways to compose objects to add new functionalities.
|Adapter||Match interfaces of different classes|
|Bridge||Separates an object’s interface from its implementation|
|Composite||A tree structure of simple and composite objects|
|Decorator||Add responsibilities to objects dynamically|
|Facade||A single class that represents an entire subsystem|
|Flyweight||A fine-grained instance used for efficient sharing|
|Proxy||An object representing another object|
3. Behavioral Design Patterns
|These design patterns are specifically concerned with communication between objects.|
|Chain of Resp.||A way of passing a request between a chain of objects|
|Command||Encapsulate a command request as an object|
|Interpreter||A way to include language elements in a program|
|Iterator||Sequentially access the elements of a collection|
|Mediator||Defines simplified communication between classes|
|Memento||Capture and restore an object’s internal state|
|Observer||A way of notifying change to a number of classes|
|State||Alter an object’s behavior when its state changes|
|Strategy||Encapsulates an algorithm inside a class|
|Template Method||Defer the exact steps of an algorithm to a subclass|
|Visitor||Defines a new operation to a class without change|