View Single Post
  #8 (permalink)  
Old February 9th, 2004, 03:31 PM
marcostraf marcostraf is offline
Friend of Wrox
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts

Hi James,
please consider revising your code, because referencing a variable of a class of which you do not have the handle is a poor design. Today it is one variable, tomorrow they are two or three...
If more than one class needs access to 'common' variable, better to put them in a separate class, and pass this class along. Besides fixing your code, your code will be much and much easier to maintein.
This is how it goes. Design class C to keep the 'shared' variables (they can be Public members or private with Get/Let/Set to allow validation, read only, saving or restoring). Your app creates one instance of class C and pass it to class A. Class A creates class B and pass C to it and go on. Notice that in this way you do not create any circular reference. If the variables are shared only between A and B, then it will be A to instanciate C.
There is also another solution (it all depends on your application). You can declare that variable only in class B and expose it, and class A (that has the handle to B) can call it from B. This is easier, but I prefer the intermediate class. It is more work and even I sometimes prefer to avoid it, but at the end I always realize that it was the better choice to start with.

Reply With Quote