# .NET Design Patterns (.NET) > Singleton, Factory, Builder, Strategy, Decorator, Repository, Unit of Work, SOLID - 24 คำถามสัมภาษณ์ - Senior - [คำถามสัมภาษณ์: .NET](https://sharpskill.dev/th/technologies/dotnet/interview-questions.md) ## 1. ปัญหาหลักของ Singleton pattern ใน .NET สมัยใหม่ที่ใช้ Dependency Injection คืออะไร? **คำตอบ** Singleton pattern แบบดั้งเดิม (static instance) ขัดแย้งกับ dependency injection เพราะสร้างการผูกมัดที่แน่นเกินไปและทำให้การทดสอบยาก ใน .NET สมัยใหม่ ควรใช้ service lifetime แบบ 'Singleton' ผ่าน DI (services.AddSingleton) ซึ่งให้การรับประกัน instance เดียวเหมือนกันพร้อมทั้งรองรับ injection, mocking และความสามารถในการทดสอบ ส่วน Singleton แบบ static จะข้าม DI container และสร้างการพึ่งพาที่ซ่อนอยู่ ## 2. ในรูปแบบ Factory Method ความแตกต่างระหว่าง Factory Method และ Abstract Factory ใน .NET คืออะไร? **คำตอบ** Factory Method กำหนดเมธอดแบบ virtual เพื่อสร้างอ็อบเจกต์ชนิดเดียว (เช่น CreateLogger) โดยให้ subclass เป็นผู้ตัดสินใจว่าจะสร้างอินสแตนซ์ของคลาสรูปธรรมใด ส่วน Abstract Factory กำหนด interface เพื่อสร้างกลุ่มของอ็อบเจกต์ที่เกี่ยวข้องกัน (เช่น IUIFactory ที่มี CreateButton, CreateTextBox) ทำให้สามารถสร้างผลิตภัณฑ์หลายตัวที่สอดคล้องกันพร้อมกันได้ Factory Method มุ่งเน้นที่ผลิตภัณฑ์เดียวด้วย polymorphism ในขณะที่ Abstract Factory จัดการผลิตภัณฑ์หลายตัวจากตระกูลเดียวกัน ## 3. ข้อได้เปรียบหลักของ Builder pattern ใน .NET สำหรับการสร้างอ็อบเจกต์ที่ซับซ้อนซึ่งมีพารามิเตอร์ทางเลือกจำนวนมากคืออะไร? **คำตอบ** Builder pattern หลีกเลี่ยง telescoping constructor (overload หลายตัวที่มีการผสมพารามิเตอร์ต่างกัน) ด้วยการมี interface แบบ fluent เพื่อสร้างอ็อบเจกต์ทีละขั้นตอน ทำให้สามารถสร้างอ็อบเจกต์ที่ซับซ้อนซึ่งมีพารามิเตอร์ทางเลือกได้อย่างอ่านง่ายและดูแลรักษาง่าย ต่างจาก constructor ที่มีพารามิเตอร์มากกว่า 10 ตัว ใน C# สมัยใหม่ init properties และ record สามารถแทนที่ Builder ได้ในกรณีง่าย ๆ แต่ Builder ยังมีประโยชน์สำหรับการตรวจสอบที่ซับซ้อนหรือการสร้างแบบหลายขั้นตอน ## มีอีก 21 คำถาม - Single Responsibility Principle (SRP) ใน SOLID คืออะไร และนำไปใช้ใน .NET อย่างไร? - หลักการ Open/Closed (OCP) ใน SOLID คืออะไร และจะนำไปใช้กับ interface ใน .NET ได้อย่างไร? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ .NET อื่นๆ - [พื้นฐาน C#](https://sharpskill.dev/th/technologies/dotnet/interview-questions/csharp-basics.md): 25 คำถาม, Junior - [LINQ & Delegates](https://sharpskill.dev/th/technologies/dotnet/interview-questions/csharp-linq-delegates.md): 20 คำถาม, Junior - [พื้นฐานสำคัญของภาษา C#](https://sharpskill.dev/th/technologies/dotnet/interview-questions/csharp-language-essentials.md): 15 คำถาม, Junior - [พื้นฐาน ASP.NET Core](https://sharpskill.dev/th/technologies/dotnet/interview-questions/aspnet-core-fundamentals.md): 18 คำถาม, Junior - [วงจรชีวิตของ request ใน ASP.NET Core](https://sharpskill.dev/th/technologies/dotnet/interview-questions/aspnet-core-request-lifecycle.md): 20 คำถาม, Junior - [Configuration & Settings](https://sharpskill.dev/th/technologies/dotnet/interview-questions/configuration-settings.md): 20 คำถาม, Junior - [วงจรชีวิตของแอปพลิเคชัน](https://sharpskill.dev/th/technologies/dotnet/interview-questions/application-lifecycle.md): 20 คำถาม, Junior - [Dependency Injection](https://sharpskill.dev/th/technologies/dotnet/interview-questions/dependency-injection.md): 24 คำถาม, Mid-Level - [Entity Framework Core](https://sharpskill.dev/th/technologies/dotnet/interview-questions/entity-framework-core.md): 25 คำถาม, Mid-Level - [Minimal APIs](https://sharpskill.dev/th/technologies/dotnet/interview-questions/minimal-apis.md): 18 คำถาม, Mid-Level - [การพัฒนา Web API](https://sharpskill.dev/th/technologies/dotnet/interview-questions/web-api-development.md): 22 คำถาม, Mid-Level - [Async ใน ASP.NET Core](https://sharpskill.dev/th/technologies/dotnet/interview-questions/async-aspnet-core.md): 20 คำถาม, Mid-Level - [Authentication & Authorization](https://sharpskill.dev/th/technologies/dotnet/interview-questions/authentication-authorization.md): 18 คำถาม, Mid-Level - [HttpClient & Networking](https://sharpskill.dev/th/technologies/dotnet/interview-questions/httpclient-networking.md): 20 คำถาม, Mid-Level - [การซีเรียลไลซ์ JSON](https://sharpskill.dev/th/technologies/dotnet/interview-questions/json-serialization.md): 20 คำถาม, Mid-Level - [Entity Framework Core ขั้นสูง](https://sharpskill.dev/th/technologies/dotnet/interview-questions/ef-core-advanced.md): 25 คำถาม, Mid-Level - [ฟีเจอร์ขั้นสูงของ C#](https://sharpskill.dev/th/technologies/dotnet/interview-questions/csharp-advanced-features.md): 20 คำถาม, Mid-Level - [Clean Architecture](https://sharpskill.dev/th/technologies/dotnet/interview-questions/clean-architecture.md): 20 คำถาม, Mid-Level - [Logging, Monitoring & Observability](https://sharpskill.dev/th/technologies/dotnet/interview-questions/logging-monitoring.md): 22 คำถาม, Mid-Level - [Unit Testing และ xUnit](https://sharpskill.dev/th/technologies/dotnet/interview-questions/unit-testing-xunit.md): 20 คำถาม, Mid-Level - [การทดสอบแบบบูรณาการ](https://sharpskill.dev/th/technologies/dotnet/interview-questions/integration-testing.md): 18 คำถาม, Mid-Level - [Docker & Containerization](https://sharpskill.dev/th/technologies/dotnet/interview-questions/docker-containerization.md): 16 คำถาม, Mid-Level - [การจัดการแพ็กเกจ NuGet](https://sharpskill.dev/th/technologies/dotnet/interview-questions/nuget-package-management.md): 16 คำถาม, Mid-Level - [Memory Management & GC](https://sharpskill.dev/th/technologies/dotnet/interview-questions/memory-management-gc.md): 22 คำถาม, Senior - [การเขียนโปรแกรมแบบรีแอกทีฟ](https://sharpskill.dev/th/technologies/dotnet/interview-questions/reactive-programming.md): 24 คำถาม, Senior - [Async/await และรูปแบบ](https://sharpskill.dev/th/technologies/dotnet/interview-questions/async-await-patterns.md): 26 คำถาม, Senior - [การเพิ่มประสิทธิภาพการทำงาน](https://sharpskill.dev/th/technologies/dotnet/interview-questions/performance-optimization.md): 22 คำถาม, Senior - [ความปลอดภัยและ Best Practices](https://sharpskill.dev/th/technologies/dotnet/interview-questions/security-best-practices.md): 24 คำถาม, Senior - [SignalR และเรียลไทม์](https://sharpskill.dev/th/technologies/dotnet/interview-questions/signalr-realtime.md): 22 คำถาม, Senior - [สถาปัตยกรรม Microservices](https://sharpskill.dev/th/technologies/dotnet/interview-questions/microservices-architecture.md): 25 คำถาม, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/th/technologies/dotnet/interview-questions/dotnet-design-patterns