base.py
"""
"""
singletonFactory = {}
def register(clz):
clazzName = clz.__name__
global singletonFactory
singletonFactory[clazzName] = clz()
return singletonFactory[clazzName]
class Base():
def __init__(self) -> None:
print(self.__class__.__name__, "created.")
def hello(self):
print("My father is Base.")
test.py
"""
"""
from factory.base import singletonFactory
bean = singletonFactory["Implement1"]
bean2 = singletonFactory["Implement1"]
bean3 = singletonFactory["Impl2"]
bean.func()
def show():
print("show")