DEV Community

Cover image for Design pattern (part 1): Wait, pattern ?
Nguyễn Huy Hoàng
Nguyễn Huy Hoàng

Posted on • Edited on

Design pattern (part 1): Wait, pattern ?

A pattern in design ? What are you talking about ?

Hey, let me tell you a little secret. As a beginner, one of the best ways to enhance your skills as a software engineer is to learn design patterns. They can make your code more flexible, maintainable, and easier to change or fix.

With the "why" out of the way, let's jump to the "how"!

What exactly does a design pattern do ?

Think of a spoon.

Is it the best tool you can use to stir your coffee ? Yes.

Are there only one way to stir your coffee using the spoon ? No.

Design patterns are the same.

They are a proven way to solve a particular problem.

They have a certain idea behind them to solve that particular problem, but the idea can be applied in many different ways.

Okay, but what does it look like ?

The descriptions of these patterns are usually formalized to enable their application in various contexts. They are usually described in the following way:

  • Intent: What is the problem that the pattern is trying to solve ? What is the general idea behind the pattern ?
  • Motivation: Explain the problem in more detail, and why the pattern is a good solution.
  • Structure: Describe the structure of the pattern, and how it is implemented.
  • Example: Provide a code example of the pattern in action.

What are the most common design patterns types ?

Most common design patterns are divided into three categories:

  • Creational patterns: The idea behind these patterns is to create objects in a controlled way so that the characteristics of the objects are suitable for the problem at hand.
  • Structural patterns: The idea behind these patterns is to make it easier to design systems by identifying a simple way to realize relationships between entities.
  • Behavioral patterns: The idea behind these patterns is to make the communication between objects more flexible and efficient.

In this post, we have discussed about design pattern definition, roles and types. We will dive deeper in the most common patterns in the next posts. Stay tuned!

Top comments (0)