Is storing class instances in a class variable a good pattern
1 answer
I really don't think this is good practice in OOP (I'm not an expert in Python). Using static (like a list foos
) is almost always a bad concept. As said in the comments, the best solution is to set up a service class (view SOA pattern in OOP) to index all your instances Foo
and then retrieve them.
However, do not assume that this is a variant of the registry template. It is rather an antipattern to this pattern, preventing proper low cohesion between classes. Granted, Python is not the best language to do strong OOP and respect that, but I would not recommend doing it anyway.
+1
source to share