Design Patterns | Set 1 (Introduction)

Design pattern provides a general reusable solution for the common problems occurs in software design. The patterns typically show relationships and interactions between classes or objects. The idea is to speed up the development process by providing well tested, proven development/design paradigm. 

It’s not mandatory to implement design patterns in your project always. Design patterns are not meant for project development. Design patterns are meant for the common problem solving. Whenever there is a need, you have to implement the suitable pattern to avoid such problems in future. To find out which pattern to use. You just have to try to understand the design patterns and it’s purposes. Only by then you will be able to pick the right one.

Goal:
• Understand the purpose and usage of each design patterns. So, you will be able to pick and implement the correct pattern as needed.

Example:
For example, in many real world situations we want to create only one instance of a class. For example, there can be only one active president of country at a time regardless of personal identity. This pattern is called Singleton pattern. Other software examples could be a single DB connection shared by multiple objects as creating a separate DB connection for every object may be costly. Similarly, there can be a single configuration manager or error manager in an application that handles all problems instead of creating multiple managers.
 
Types of Design Patterns
There are mainly three types of design patterns:
1. Creational
These design patterns are all about class instantiation or object creation. These patterns can be further categorized into Class-creational patterns and object-creational patterns. While class-creation patterns use inheritance effectively in the instantiation process, object-creation patterns use delegation effectively to get the job done.

Creational design patterns are Factory Method, Abstract Factory, Builder, Singleton, Object Pool and Prototype.

2. Structural
These design patterns are about organizing different classes and objects to form larger structures and provide new functionality.

Structural design patterns are Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Private Class Data and Proxy.

3. Behavioral
Behavioral patterns are about identifying common communication patterns between objects and realize these patterns.

Behavioral patterns are Chain of responsibility, Command, Interpreter, Iterator, Mediator, Memento, Null Object, Observer, State, Strategy, Template method, Visitor

References:
https://sourcemaking.com/design_patterns
https://sourcemaking.com/design_patterns/singleton

This article is contributed by Abhijit Saha. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.



My Personal Notes arrow_drop_up

Improved By : Sachin Araballi, Gopip



Article Tags :

18


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.