views:

29

answers:

1

While working on my hobby projects i split code in to background operations and gui operations. So i end up having library objects that does the actual work and gui objects that represent menus, frames and such. The thing that bugs me every time is that i end up having lots of objects that has to know about other objects. Such as toolbar object needs to know about the mainframe and main menu needs to know about both frame and toolbar so i end up passing references to lots of objects through constructors. While it works i can not imagine windows or darwin code passing 100 references to other components.

So my question is what is the preferred way of keeping objects with out passing a bunch of references to each other?

+1  A: 

Separation of Concerns : make each object have only one responsibility.

The goal here is to make sure each object to it's minimal functionnality and do it well. Then compose your system with your objects. That way you get a system with tiny classes that are composants of bigger classes that "manage" parts of your system and communicate together. The dependencies between those classes are then simple.

I'm sure I'm not totally clear here, you should try to look at how is organized some big and complex object-oriented libraries (like Ogre if you're interested in real time 3D rendering).

Klaim