What are design patterns?
Design Pattern is a technique in object-oriented programming, it's quite important and every good programmer must know. Used frequently in OOP languages. It will give you "designs", solutions to solve common programming problems. The problems you encounter may come up with your own solutions, but they may not be optimal. Design Patterns help you solve problems in the most optimal way.
Each pattern describes a problem that occurs over and over, and presents the focus of the solution to the problem, in a way that you can use it over and over again without thinking.
Classification Design Patterns
In 1994, four authors Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides published a book titled Design Patterns - Elements of Reusable Object-Oriented Software, which originated the concept of design patterns in programming.
These four authors are widely known as the Gang of Four. From the perspective of four people, the design pattern is mainly based on the following rules of object-oriented design.
- Program the interface, but not implement it.
- Prioritize composition composition over inheritance.
The design pattern currently has 23 patterns defined in "Design patterns Elements of Reusable Object Oriented Software" and is divided into three groups.
1. Creational Patterns
This group includes 5 patterns: Factory Method, Abstract Factory, Builder, Prototype, Singleton.
These design patterns provide a solution to creating objects and hiding the logic of its creation, instead of creating objects directly using the new keyword. This makes the program more flexible in deciding which objects need to be created in different situations.
2. Structural Patterns
This group includes 7 patterns: Adapter, Bridge, Composite, Decorator, Facade, Flyweight and Proxy.
These design patterns relate to the class and components of the object. It is used to establish and define relationships between objects.
3. Behavioral Patterns
This group includes 11 patterns: Interpreter, Template Method, Chain of Responsibility, Command, Iterator, Mediator, Memento, Observer, State, Strategy and Visitor.
This group is used to perform the behavior of objects or communicate between objects.