Factory pattern بغیر ان کی مکمل class کی تفصیل کے objects بنانے کا طریقہ فراہم کرتا ہے — یہ ایک method یا class ہے جو object کی تخلیق کو handle کرتی ہے، اور یہ فیصلہ کرتی ہے کہ کون سی type کو instantiate کرنا ہے۔ یہ object کی تخلیق کو centralize اور abstract کرتا ہے، code کو concrete classes سے الگ کرتا ہے۔
Factory pattern کیا کرتا ہے
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
