Factory पैटर्न ऑब्जेक्ट्स को उनकी सटीक क्लास निर्दिष्ट किए बिना बनाने का एक तरीका प्रदान करता है — एक मेथड या क्लास जो ऑब्जेक्ट निर्माण को संभालती है और तय करती है कि किस प्रकार को इंस्टैंशिएट करना है। यह ऑब्जेक्ट निर्माण को केंद्रीकृत और अमूर्त करता है, और कोड को कंक्रीट क्लासों से decouple करता है।
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
