يوفر نمط Factory طريقة لإنشاء الكائنات دون تحديد فئتها الدقيقة — دالة أو فئة تتعامل مع إنشاء الكائنات، وتقرر أي نوع يتم إنشاء مثيل له. يجمع ويجرد إنشاء الكائنات، مما يفصل الكود عن الفئات الملموسة.
ما يفعله نمط Factory
FACTORY → encapsulate object CREATION (instead of calling constructors directly):
→ a factory method/class decides WHICH class to instantiate and creates it
→ the caller asks the factory for an object (by type/parameter) → gets the right object
WITHOUT knowing/specifying the concrete class
→ decouples code from CONCRETE classes; centralizes creation logic
