Factory pattern ले objects सिर्जना गर्न बिना तिनको सटीक class निर्दिष्ट गरी एक तरिका प्रदान गर्छ — एक method वा class जसले object creation सम्भाल्छ, कुन type instantiate गर्ने भनी निर्णय गर्छ। यसले object creation लाई केन्द्रीकृत र अमूर्त बनाउँछ, कोडलाई 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
