Corak Factory menyediakan cara untuk mencipta objek tanpa menentukan kelas tepatnya — sesuatu kaedah atau kelas yang mengendalikan penciptaan objek, memutuskan jenis mana untuk di-instantiate. Ia memusatkan dan mengabstrakkan penciptaan objek, memisahkan kod daripada kelas konkrit.
Apa yang dilakukan corak 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
