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