What are Design Patterns?

By FoxLearn 12/27/2024 9:40:19 AM   5.14K
This article will introduce you briefly about Design Patterns.

What are design patterns?

Design Patterns are techniques in object-oriented programming (OOP) that provide optimal solutions to common programming problems. They are essential for every good programmer to know and are widely used in OOP languages like Java, C#, and JavaScript. These patterns are not language-specific and can be applied across various programming languages.

Each design pattern addresses a recurring problem and offers a reusable solution, helping developers solve problems efficiently without reinventing the wheel. By using design patterns, programmers can implement solutions that are more optimal than their own potentially suboptimal approaches.

Classification Design Patterns

In 1994, Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides, known as the Gang of Four, published the book Design Patterns: Elements of Reusable Object-Oriented Software, which introduced the concept of design patterns in programming.

The book emphasizes key object-oriented design principles, including programming to an interface rather than an implementation, and prioritizing composition over inheritance. It defines 23 design patterns, which are grouped into three categories.

1. Creational Patterns

This group includes 5 patterns: Factory Method, Abstract Factory, Builder, Prototype, Singleton.

creation design pattern

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.

Structural Design Patterns

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.

Behavioral Design Patterns

This group is used to perform the behavior of objects or communicate between objects.