MATLAB: “findobj” for user defined class

classfindobjoop

Does anyone has an idea whether is there a way to fetch all instances of certain class from a up-level instance of different classes?
For example, instance A1 of Class A and instance B1 of Class B both contain instances of Class C. Is there a way to call something like "findobj" to get all instances of Class C from A1 and B1?
Thanks.

Best Answer

While @Steve Lord has answered the question "why you shouldn't do this," I'll go ahead and try to answer how you can do this, and possibly shoot yourself in the foot - due to inconsistent state.
To do this, you want to use a factory design pattern and keep a log of all instantiated objects in a singleton.