Design a factory that returns the same instance for a given key
Constraints
Example
>>> class Counter: ... def __init__(self, start=0): ... self.value = start ... def increment(self): ... self.value += 1 >>> f = SingletonFactory() >>> c1 = f.get_instance(Counter, 10) >>> c2 = f.get_instance(Counter) >>> c1 is c2 True >>> c1.increment() >>> c1.value 11 >>> c2.value 11 >>> f.instance_count() 1 >>> f.get_instance(list) [] >>> f.instance_count() 2
Recent Submissions
No submissions yet — hit Run Tests to try!
Hints