工厂模式,一个工厂实例化一个指定类。
class NeedToInstanceClass:
def __init__(self):
pass
class Factory(object):
def __init__(self):
super().__init__()
self.cls = NeedToInstanceClass
def get_instance(self):
return self.cls()
if __name__ == '__main__':
factory = Factory()
print("class name of factory product instance:", factory.get_instance().__class__.__name__)