# 21.ลองใช้คลาสแบบจริงจังบ้าง

💬 ตั้งแต่บทที่ 16\~20 เราได้เห็นทฤษฎีของคลาสกันมาเยอะพอสมควรละ คราวนี้เราจะมาลองใช้คลาสแบบจริงๆจังๆดูบ้างว่ามันจะออกมาเป็นแบบที่คิดไว้หรือเปล่านะ

{% embed url="<https://www.youtube.com/watch?v=eo2lBkgZ5N0&list=PLUjAn8nwWnijERZ3HpzBk7NfSrau74_lQ&index=36>" %}

## 🎥 ใช้คลาสเขียนเกมเป่ายิงฉุบ

{% embed url="<https://www.youtube.com/watch?v=J6qxl8F0Gkw&list=PLUjAn8nwWnijERZ3HpzBk7NfSrau74_lQ&index=37>" %}

## 🎯 สรุปสั้นๆ

### 👨‍🚀 การใช้งานคลาส

จะเห็นว่าเวลาที่ผมสร้างคลาสขึ้นมาซักตัว ผมจะมองก่อนว่า**มันมีอะไรที่จำเป็นต้องใช้ในคลาสนั้นๆบ้าง**แล้วผมค่อยเอาไปใส่คลาสนั้นๆ ส่วนเวลาจะสร้าง method ผมก็จะมองว่า**คลาสนั้นมันต้องทำอะไรได้บ้าง**และ**ความสามารถนั้นหรือ method นั้นควรอยู่กับคลาสไหน** แล้วค่อยสร้าง method ให้กับคลาสที่มันควรจะอยู่ แล้วหลังจากที่มันทำงานได้หมดละ ผมค่อยแก้ไขโค้ดให้มันกระชับขึ้นอีกทีครับ หรือเราเรียกว่าการทำ **Refactor Code**

{% hint style="success" %}
**Refactor Code**\
คือการจัดการให้โค้ดของเรา อ่านง่าย สามารถจัดการได้ง่ายขึ้น หรือคำศัพท์ที่เราใช้เป็นประจำคือ การทำให้มันสามารถ **maintenance** ได้ง่ายขึ้นครับ ซึ่งเรื่องการ Refactor Code แบบลงลึกๆ ผมจะขอแบ่งเอาไว้อธิบายในคอร์ส **Clean Code** แทนนะครับ
{% endhint %}


---

# 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/csharp101/intermediate/demo-class.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.
