Modeli Factory ofron një mënyrë për të krijuar objekte pa specifikuar klasën e tyre ekzakte — një metodë ose klasë që menaxhon krijimin e objektit, duke vendosur se cili lloj të instantohet. Ai centralizon dhe abstrakt krijimin e objektit, duke shkëputur kodin nga klasat konkrete.
Çfarë bën modeli 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
