tags:

views:

65

answers:

1

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
I forgot to add i can't pass it as an argument. Good solution. Thanks.
Barrett Ames