OO Design - Object Accessibility
Posted on 2004-07-30
This is less a c# question, and more of an object oriented design question in general, but since I'm using c#, I'm posting it in here.
I am a self taught programmer (books, tinkering, etc) and I seem to be having the same problem over and over again when I design more complex apps. Here's an example:
Say that there are three classes: Class A, B, and C.
Class A contains an instance of Class B, and Class B contains an instance of Class C.
However, both Class B and Class C need to access an object that's a member of Class A.
The only way i can think of to accomplish this, is to add an instance of the object to Class B and C, and pass the required object from Class A by reference.
A. Is there a better way to do this?
B. Is this problem a result of bad design? And if so, how could the design be changed to avoid it?