# iOS Design Patterns (iOS) > Singleton, Factory, Builder, Observer, Coordinator, Repository, Dependency Injection, SOLID - 24 คำถามสัมภาษณ์ - Senior - [คำถามสัมภาษณ์: iOS](https://sharpskill.dev/th/technologies/ios/interview-questions.md) ## 1. Pattern ใดรับประกันว่ามี instance ของ class เพียงตัวเดียวตลอดทั้งแอปพลิเคชัน? **คำตอบ** Singleton pattern จำกัดการสร้าง instance ให้เหลือเพียง instance ส่วนกลางตัวเดียว ใน iOS ช่วยให้เข้าถึงทรัพยากรที่ใช้ร่วมกัน เช่น การตั้งค่าหรือ manager แบบรวมศูนย์ได้ อย่างไรก็ตาม Singleton ลดความสามารถในการทดสอบ เพราะสร้างการพึ่งพาส่วนกลางที่ mock ได้ยาก ## 2. Pattern ใดที่ทำให้การสร้างอ็อบเจกต์เป็นนามธรรมโดยไม่เปิดเผยตรรกะการสร้าง instance ที่แท้จริง? **คำตอบ** Factory pattern ห่อหุ้มการสร้างอ็อบเจกต์ไว้ใน method หรือ class เฉพาะ ซึ่งช่วยให้แก้ไขตรรกะการสร้างได้โดยไม่กระทบโค้ดฝั่ง client ใน iOS factory method ช่วยลดความซับซ้อนในการจัดการ dependency ที่ซับซ้อนและทำให้ทดสอบได้ง่ายผ่านการแทนที่ที่สะดวก ## 3. Pattern ใดที่สร้างอ็อบเจกต์ที่ซับซ้อนทีละขั้นตอนพร้อมแยกการสร้างออกจากการแสดงผล? **คำตอบ** Builder pattern ช่วยให้สร้างอ็อบเจกต์ที่มีพารามิเตอร์ทางเลือกจำนวนมากได้โดยไม่ต้อง overload constructor ใน iOS ช่วยเพิ่มความชัดเจนของโค้ดและทำให้ดูแลรักษาง่ายขึ้น ต่างจาก Factory ที่คืนค่าทันที Builder อนุญาตให้กำหนดค่าแบบค่อยเป็นค่อยไปและลื่นไหล ## มีอีก 21 คำถาม - Pattern ใดที่กำหนดความสัมพันธ์แบบหนึ่ง-ต่อ-หลายที่ observer ได้รับการแจ้งเตือนการเปลี่ยนแปลงโดยอัตโนมัติ? - การใช้งานหลักของ Factory ในการสร้างอ็อบเจกต์ด้วยตรรกะเงื่อนไขคืออะไร? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ iOS อื่นๆ - [พื้นฐาน Swift](https://sharpskill.dev/th/technologies/ios/interview-questions/swift-basics.md): 25 คำถาม, Junior - [พื้นฐานภาษา Swift](https://sharpskill.dev/th/technologies/ios/interview-questions/swift-language-essentials.md): 15 คำถาม, Junior - [พื้นฐาน UIKit](https://sharpskill.dev/th/technologies/ios/interview-questions/uikit-fundamentals.md): 18 คำถาม, Junior - [วงจรชีวิตของ UIViewController](https://sharpskill.dev/th/technologies/ios/interview-questions/uiviewcontroller-lifecycle.md): 20 คำถาม, Junior - [UserDefaults & Keychain](https://sharpskill.dev/th/technologies/ios/interview-questions/userdefaults-keychain.md): 20 คำถาม, Junior - [วงจรชีวิตของแอปพลิเคชัน](https://sharpskill.dev/th/technologies/ios/interview-questions/app-lifecycle.md): 20 คำถาม, Junior - [Auto Layout & Constraints](https://sharpskill.dev/th/technologies/ios/interview-questions/auto-layout-constraints.md): 24 คำถาม, Mid-Level - [UITableView & UICollectionView](https://sharpskill.dev/th/technologies/ios/interview-questions/uitableview-uicollectionview.md): 25 คำถาม, Mid-Level - [พื้นฐาน SwiftUI](https://sharpskill.dev/th/technologies/ios/interview-questions/swiftui-basics.md): 18 คำถาม, Mid-Level - [การจัดการ State ใน SwiftUI](https://sharpskill.dev/th/technologies/ios/interview-questions/swiftui-state-management.md): 22 คำถาม, Mid-Level - [การนำทาง SwiftUI](https://sharpskill.dev/th/technologies/ios/interview-questions/swiftui-navigation.md): 18 คำถาม, Mid-Level - [Networking & URLSession](https://sharpskill.dev/th/technologies/ios/interview-questions/networking-urlsession.md): 20 คำถาม, Mid-Level - [Codable และการแยกวิเคราะห์ JSON](https://sharpskill.dev/th/technologies/ios/interview-questions/codable-json-parsing.md): 20 คำถาม, Mid-Level - [Core Data](https://sharpskill.dev/th/technologies/ios/interview-questions/core-data.md): 22 คำถาม, Mid-Level - [การเขียนโปรแกรมเชิงโปรโตคอล](https://sharpskill.dev/th/technologies/ios/interview-questions/protocol-oriented-programming.md): 20 คำถาม, Mid-Level - [สถาปัตยกรรม MVVM](https://sharpskill.dev/th/technologies/ios/interview-questions/mvvm-architecture.md): 20 คำถาม, Mid-Level - [การแจ้งเตือนแบบ Push](https://sharpskill.dev/th/technologies/ios/interview-questions/push-notifications.md): 18 คำถาม, Mid-Level - [Unit Testing และ XCTest](https://sharpskill.dev/th/technologies/ios/interview-questions/unit-testing-xctest.md): 20 คำถาม, Mid-Level - [การทดสอบ UI](https://sharpskill.dev/th/technologies/ios/interview-questions/ui-testing.md): 18 คำถาม, Mid-Level - [Xcode และระบบ Build](https://sharpskill.dev/th/technologies/ios/interview-questions/xcode-build-system.md): 16 คำถาม, Mid-Level - [Swift Package Manager](https://sharpskill.dev/th/technologies/ios/interview-questions/swift-package-manager.md): 16 คำถาม, Mid-Level - [Memory Management & ARC](https://sharpskill.dev/th/technologies/ios/interview-questions/memory-management-arc.md): 22 คำถาม, Senior - [Combine Framework](https://sharpskill.dev/th/technologies/ios/interview-questions/combine-framework.md): 24 คำถาม, Senior - [Concurrency & async/await](https://sharpskill.dev/th/technologies/ios/interview-questions/concurrency-async-await.md): 26 คำถาม, Senior - [การเพิ่มประสิทธิภาพ](https://sharpskill.dev/th/technologies/ios/interview-questions/performance-optimization.md): 22 คำถาม, Senior - [ความปลอดภัยและการเข้ารหัส](https://sharpskill.dev/th/technologies/ios/interview-questions/security-encryption.md): 20 คำถาม, Senior - [SwiftUI Advanced](https://sharpskill.dev/th/technologies/ios/interview-questions/swiftui-advanced.md): 22 คำถาม, Senior - [สถาปัตยกรรมแอปพลิเคชัน iOS](https://sharpskill.dev/th/technologies/ios/interview-questions/ios-app-architecture.md): 22 คำถาม, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/th/technologies/ios/interview-questions/ios-design-patterns