I saw this in code for someone and thought it was an elegant way to solve this particular problem, but it probably violates the good OO principles in an epic way.
In the constructor for a set of classes, all of which are derived from a common base class, it requires a reference to the instancing class that must be passed. For example, photos Foo Foo_i = new (this);
Then, later, Foo will call methods in the instancing class to get information about itself and other objects contained in the instancing class.
On the one hand, this simplifies TON code, which models a 5-layer tree structure in equipment (agents connect to ports on several switches, etc.). On the other hand, these objects are pretty closely related to each other in a way that seems pretty wrong, but I don't know enough about OOA & D to lay my finger on it.
So, is everything all right? Or is it the OO equivalent for the goto statement?
source share