Creational pattern จัดการเรื่องการสร้างอ็อบเจ็กต์ คือวิธีที่อ็อบเจ็กต์ถูกสร้าง ทำให้ยืดหยุ่น และแยกออกจากโค้ดที่ใช้มัน ซึ่งรวมถึง Singleton, Factory, Builder, Prototype และ Abstract Factory
Creational pattern ตอบโจทย์อะไร
CREATIONAL patterns abstract and control HOW objects are CREATED:
→ instead of directly calling constructors everywhere (rigid, coupled), creational
patterns make object creation flexible, decoupled, and manageable
→ they help create objects in a way suited to the situation, decoupled from concrete classes
Creational pattern หลัก ๆ
SINGLETON → ensure only ONE instance of a class (single shared object)
FACTORY METHOD → create objects without specifying the exact class (defer to a method/subclass)
ABSTRACT FACTORY → create FAMILIES of related objects (without specifying concrete classes)
BUILDER → construct complex objects step-by-step (separate construction from representation);
good for objects with many optional parts/parameters
PROTOTYPE → create new objects by CLONING an existing one (copy a prototype)
