# Structural Patterns

![](/files/-MLCtezzw94mmub0yvWZ)

{% hint style="success" %}
**Best Practice**\
หลักในการออกแบบที่ดีคือ **มันต้องดิ้นได้โดยไม่ต้องแก้ไขโค้ดเดิม** หรือที่เรารู้จักในชื่อของ [**OCP** ](https://www.saladpuk.com/basic/solid/ocp)นั่นเอง ถ้าสนใจก็กดที่ชื่อมันเพื่อเข้าไปศึกษาต่อได้เบย เพราะมันจะช่วยให้โค้ดของเราเพิ่มความสามารถใหม่ๆเข้าไปได้ โดยที่เราไม่จำเป็นต้องแก้ไขโค้ดเดิมเลยนั่นเอง 😉
{% endhint %}

เมื่อพูดถึงการออกแบบว่าเราควรจะมีคลาสอะไรบ้าง? แต่ละคลาสควรมีโครงสร้างยังไงถึงจะช่วยให้เราทำงานได้เร็วขึ้น ไม่ซับซ้อนจนเกินไป บลาๆ **ดชแมวน้ำ** แนะนำให้ศึกษา Design Patterns ในกลุ่มของ Structural Patterns ด้านล่างนี้ฮั๊ฟ

## 😭 ใครช่วยแก้ปัญหานี้ได้บ้าง ?

ในกุล่มของ **Structural Patterns** นี้มีพระเอกหลายตัวเลยที่จะมาช่วยแก้ปัญหาเรื่องการออกแบบในระดับโครงสร้างกันเลยทีเดียว ซึ่งเจ้าตัว design แต่ละตัวมันจะเก่งกันคนละเรื่อง ขึ้นอยู่กับว่าปัญหาที่เราเจอเป็นแบบไหน ดังนั้นไปดูว่าแต่ละตัวมันช่วยแก้ปัญหาอะไรเลยละกัน

### [🔌 Adapter Pattern](https://www.saladpuk.com/beginner-1/design-patterns/structural/adapter-pattern)

> เปลี่ยนของ 2 อย่างที่ทำงานด้วยกันยากๆ มาทำงานด้วยกันได้ง่าย

### [📪 **Proxy Pattern**](https://www.saladpuk.com/beginner-1/design-patterns/structural/proxy-pattern)

> ควบคุม object ให้ทำงานดั่งใจ

* **Bridge Pattern** (ว่างเดี๋ยวกลับมาเขียน)
* **Composite pattern** (ว่างเดี๋ยวกลับมาเขียน)
* **Decorator Pattern** (ว่างเดี๋ยวกลับมาเขียน)
* **Facade Pattern** (ว่างเดี๋ยวกลับมาเขียน)
* **Flyweight pattern** (ว่างเดี๋ยวกลับมาเขียน)

{% hint style="danger" %}
**คำเตือน**\
ไม่ควรนำ Design Patterns ไปใช้ โดยไม่ได้ชั่ง ผลดี/ผลเสีย ให้เรียบร้อยก่อน เพราะมันจะทำให้โค้ดเราซับซ้อนโดยไม่จำเป็น แล้วจะแก้ไขปรับปรุงอะไรต่างๆก็จะกลายเป็นเต่า แต่**จงศึกษา Design Patterns เพื่อเรียนรู้หลักในการออกแบบ** เพื่อจะได้รู้ว่าเมื่อไหร่ไม่ควรใช้ Pattern
{% endhint %}

{% hint style="info" %}
คอร์สนี้กำลังค่อยๆเขียนอยู่ ใครที่ไม่อยากพลาดอัพเดทก็เข้าไปกดติดตามที่ลิงค์ [**Mr.Saladpuk**](https://www.facebook.com/mr.saladpuk) ได้เลย ส่วนใครที่อยากศึกษา pattern ตัวไหนล่วงหน้าก็ไปอ่านบทความเก่าได้ที่ลิงค์นี้ [🤴 Design Patterns](https://saladpuk.gitbook.io/learn/software-design/designpatterns) (อ่านแล้วเมากาวไม่รู้ด้วยนะ) **+ ในคอร์สนี้จะเริ่มอธิบาย Pattern แต่ละตัวจากกลุ่มนี้ก่อนนะครัช**
{% endhint %}

![ช่องทางสนับสนุนค่าอาหารแมวน้ำกั๊ฟ 😘](/files/-MKNmp9HEqzREDsXrZ0H)


---

# 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://www.saladpuk.com/beginner-1/design-patterns/structural.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.
