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.
• Understand the purpose and usage of each design patterns. So, you will be able to pick and implement the correct pattern as needed.
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:
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.
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.
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
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.
- Design Patterns | Set 2 (Factory Method)
- Observer Pattern | Set 1 (Introduction)
- Singleton Design Pattern | Implementation
- The Decorator Pattern | Set 2 (Introduction and Design)
- Decorator Pattern | Set 3 (Coding the Design)
- Strategy Pattern | Set 1 (Introduction)
- Flyweight Design Pattern
- Singleton Design Pattern | Introduction
- Java Singleton Design Pattern Practices with Examples
- How to design a parking lot using object-oriented principles?
- Design data structures and algorithms for in-memory file system
- Facade Design Pattern | Introduction
- Proxy Design Pattern
- Composite Design Pattern
- Prototype Design Pattern