samedi 12 juin 2021

Abstract factory pattern general outline

I am new to design patterns and got a little confused about abstract patterns. I feel like I did not get the concept clearly. Here is my understanding of how Abstract factories look like.

from abc import ABC, abstractmethod

class AbstractFactory(ABC):

    @abstractmethod
    def create_object(self):
        pass

class Factory_family_1(AbstractFactory):

    def __init__(self):
        pass
    
    def common_functionalities(self):
        pass

    def create_object(self):
        if "conditon 1":
            return Family_1_instance_1()
        elif "condition 2":
            return Family_1_instance_2()

class Factory_family_2(AbstractFactory):

    def __init__(self): pass
    
    def common_functionalities(self): pass
    
    def create_object(self):
        
        if "conditon 1":
            return Family_2_instance_1()
        
        elif "condition 2":
            return Family_2_instance_2()        

class Family_1_instance_1(Factory_family_1): pass
class Family_1_instance_2(Factory_family_1): pass
class Family_2_instance_1(Factory_family_2): pass
class Family_2_instance_2(Factory_family_2): pass

Correct me, please, if I misunderstood the concept.

Aucun commentaire:

Enregistrer un commentaire