I did a complex class and now I have to track it and register it in a bigger class for management.
The problem, is that the complex class may create a new instance of itself. Therefore, I have to detect this new creation in my manager.
The other problem is that there is not only one manager. They're used like a session manager. Each has a initial complex object in it. If the complex object instantiates a new instance of itself, only the good manager must be warned.
Here is an example of code to present my problem:
class Foo:
def create_another(self):
# Do something
return Foo()
class Manager:
def __init__(self):
init_object = SomeDecorator(Foo()) # I guess there will be a decorator
self.objects = [init_objects]
m1 = Manager()
assert len(m1.objects) == 1
m1.objects[0].create_another()
assert len(m1.objects) == 2
m2 = Manager()
assert len(m1.objects) == 2
assert len(m2.objects) == 1
m1.objects[0].create_another()
assert len(m1.objects) == 3
assert len(m2.objects) == 1
m2.objects[0].create_another()
assert len(m1.objects) == 3
assert len(m2.objects) == 2