I have an instance of Class A that I want to refer to in the constructor of multiple instances of B. How can I refer to that particular instance of Class A in each new instance of B?
+2
A:
If you only ever want to have one instance of class A, use a Singleton Pattern. You can then have class B's constructor refer to the singleton. Otherwise, the best way to refer to an object of class A in the constructor of class B is to pass it as an argument.
Parappa
2009-11-08 07:26:02
I forgot to add i can't pass it as an argument. Good solution. Thanks.
Barrett Ames
2009-11-08 15:04:58