# Design pattern

{% hint style="info" %}
Các framework và thư viện hàng ngày cũng được xây dựng dựa trên design pattern.
{% endhint %}

## Design pattern có thực sự cần thiết?

Design pattern trong thiết kế phần mềm là những phương pháp giải quyết các vấn đề phổ biến mà có thể tái sử dụng được. Mặc dù có những lập trình viên cho rằng design pattern không cần thiết hoặc khó áp dụng, thực tế sử dụng một design pattern thích hợp có thể giúp viết code dễ hiểu, dễ bảo trì và tăng tính thẩm mỹ của code.

| Creational       | Structure | Behavioral              |
| ---------------- | --------- | ----------------------- |
| Abstract factory | Adapter   | Chain of responsibility |
| Builder          | Bridge    | Command                 |
| Factory          | Composite | Interpreter             |
| Prototype        | Decorator | Iterator                |
| #**Singleton**   | Facade    | Mediator                |
| Flyweight        | Memento   | Memento                 |
|                  | Proxy     | Observer                |
|                  |           | Strategy                |
|                  |           | Template Method         |
|                  |           | Visitor                 |

Một điểm quan trọng nữa của design pattern là nó là một ngôn ngữ chung của các lập trình viên. Khi người khác đọc code của bạn và nhận ra một design pattern được sử dụng, họ có thể nhanh chóng hiểu mục đích và cách thức hoạt động của code đó.

Ví dụ, nếu bạn sử dụng decorator pattern trong dự án, người đọc code có thể nhận biết rằng đoạn code đó được sử dụng để "trang trí" hoặc mở rộng chức năng cho các tính năng chính. Điều này giúp họ tập trung vào giải quyết các vấn đề nghiệp vụ thay vì phải tìm hiểu chi tiết từng dòng code.

Hiểu rõ về design pattern và áp dụng chúng một cách chính xác có ý nghĩa quan trọng.

Chúng ta sẽ cùng tìm hiểu các design pattern phổ biến cho FE và BE:

{% content-ref url="design-pattern/front-end-design-pattern" %}
[front-end-design-pattern](https://vick7-education.gitbook.io/freshforfresh/design-pattern/front-end-design-pattern)
{% endcontent-ref %}

{% content-ref url="design-pattern/back-end-design-pattern" %}
[back-end-design-pattern](https://vick7-education.gitbook.io/freshforfresh/design-pattern/back-end-design-pattern)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://vick7-education.gitbook.io/freshforfresh/design-pattern.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
