# Go Design Patterns (Go) > Singleton, Factory, Builder, Strategy, Decorator, Adapter, functional options, SOLID - 24 คำถามสัมภาษณ์ - Senior - [คำถามสัมภาษณ์: Go](https://sharpskill.dev/th/technologies/go/interview-questions.md) ## 1. ข้อดีหลักของ pattern Functional Options ใน Go คืออะไร? **คำตอบ** Pattern Functional Options ช่วยให้สร้าง API ที่กำหนดค่าได้พร้อมพารามิเตอร์ที่เป็นทางเลือกโดยไม่ต้อง overload constructor มันหลีกเลี่ยงการมี constructor หลายตัวที่มี signature ต่างกันและให้ API ที่ขยายได้และอ่านง่าย Pattern นี้เป็น idiomatic ใน Go เพราะใช้ประโยชน์จาก first-class function และหลีกเลี่ยงค่าเริ่มต้นที่กำกวม ## 2. แนวทางใดที่แนะนำสำหรับการ implement pattern Singleton ใน Go? **คำตอบ** ใน Go pattern Singleton ถูก implement ได้ดีที่สุดด้วย sync.Once ซึ่งรับประกันการเริ่มต้นแบบ thread-safe และ lazy initialization แนวทางนี้หลีกเลี่ยง mutex แบบ manual และ double-checked locking ซึ่งมักเกิดข้อผิดพลาด sync.Once รับประกันว่าฟังก์ชันจะถูกเรียกใช้เพียงครั้งเดียวแม้จะมีหลาย goroutine ทำงานพร้อมกัน ## 3. หลักการ SOLID ใดที่สนับสนุนการใช้ interface ใน Go? **คำตอบ** หลักการ Dependency Inversion ระบุว่าโมดูลระดับสูงไม่ควรขึ้นกับโมดูลระดับต่ำ แต่ควรขึ้นกับสิ่งที่เป็นนามธรรม (interface) ใน Go สิ่งนี้แปลเป็นการรับ interface และคืนค่าเป็นชนิดที่เป็นรูปธรรม หลักการนี้ช่วยให้การทดสอบ (mocking) การลดการพึ่งพากัน และการบำรุงรักษาโค้ดทำได้ง่ายขึ้น ## มีอีก 21 คำถาม - จะ implement pattern Factory ใน Go แบบ idiomatic ได้อย่างไร? - บทบาทหลักของ Adapter pattern คืออะไร? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ Go อื่นๆ - [พื้นฐาน Go](https://sharpskill.dev/th/technologies/go/interview-questions/go-basics.md): 25 คำถาม, Junior - [โครงสร้างข้อมูล Go](https://sharpskill.dev/th/technologies/go/interview-questions/go-data-structures.md): 20 คำถาม, Junior - [อินเทอร์เฟซใน Go](https://sharpskill.dev/th/technologies/go/interview-questions/go-interfaces.md): 18 คำถาม, Junior - [การจัดการข้อผิดพลาด](https://sharpskill.dev/th/technologies/go/interview-questions/error-handling.md): 20 คำถาม, Junior - [พื้นฐาน Goroutine](https://sharpskill.dev/th/technologies/go/interview-questions/goroutines-basics.md): 20 คำถาม, Junior - [Channels](https://sharpskill.dev/th/technologies/go/interview-questions/channels.md): 22 คำถาม, Junior - [Go Modules](https://sharpskill.dev/th/technologies/go/interview-questions/go-modules.md): 18 คำถาม, Mid-Level - [เซิร์ฟเวอร์ HTTP](https://sharpskill.dev/th/technologies/go/interview-questions/http-server.md): 24 คำถาม, Mid-Level - [ไคลเอนต์ HTTP](https://sharpskill.dev/th/technologies/go/interview-questions/http-client.md): 18 คำถาม, Mid-Level - [การเข้ารหัส JSON](https://sharpskill.dev/th/technologies/go/interview-questions/json-encoding.md): 20 คำถาม, Mid-Level - [Database/SQL](https://sharpskill.dev/th/technologies/go/interview-questions/database-sql.md): 22 คำถาม, Mid-Level - [แพ็กเกจ context](https://sharpskill.dev/th/technologies/go/interview-questions/context-package.md): 20 คำถาม, Mid-Level - [Testing](https://sharpskill.dev/th/technologies/go/interview-questions/testing.md): 22 คำถาม, Mid-Level - [รูปแบบ Concurrency](https://sharpskill.dev/th/technologies/go/interview-questions/concurrency-patterns.md): 24 คำถาม, Mid-Level - [ไพรมิทีฟการซิงโครไนซ์](https://sharpskill.dev/th/technologies/go/interview-questions/sync-primitives.md): 22 คำถาม, Mid-Level - [เฟรมเวิร์กเว็บ Go](https://sharpskill.dev/th/technologies/go/interview-questions/go-web-frameworks.md): 20 คำถาม, Mid-Level - [การออกแบบ REST API](https://sharpskill.dev/th/technologies/go/interview-questions/rest-api-design.md): 20 คำถาม, Mid-Level - [gRPC](https://sharpskill.dev/th/technologies/go/interview-questions/grpc.md): 22 คำถาม, Mid-Level - [Reflection](https://sharpskill.dev/th/technologies/go/interview-questions/reflection.md): 20 คำถาม, Senior - [การจัดการหน่วยความจำ](https://sharpskill.dev/th/technologies/go/interview-questions/memory-management.md): 24 คำถาม, Senior - [การเพิ่มประสิทธิภาพการทำงาน](https://sharpskill.dev/th/technologies/go/interview-questions/performance-optimization.md): 22 คำถาม, Senior - [Generics](https://sharpskill.dev/th/technologies/go/interview-questions/generics.md): 20 คำถาม, Senior - [Microservices](https://sharpskill.dev/th/technologies/go/interview-questions/microservices.md): 24 คำถาม, Senior - [ความปลอดภัยและการยืนยันตัวตน](https://sharpskill.dev/th/technologies/go/interview-questions/security-authentication.md): 24 คำถาม, Senior - [Docker & Containerization](https://sharpskill.dev/th/technologies/go/interview-questions/docker-containerization.md): 20 คำถาม, Senior - [Kubernetes Basics](https://sharpskill.dev/th/technologies/go/interview-questions/kubernetes-basics.md): 22 คำถาม, Senior - [Go ขั้นสูง](https://sharpskill.dev/th/technologies/go/interview-questions/advanced-go.md): 20 คำถาม, Senior - [การพัฒนา CLI](https://sharpskill.dev/th/technologies/go/interview-questions/cli-development.md): 20 คำถาม, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/th/technologies/go/interview-questions/design-patterns