开发者

Same instance referred to by multiple constructors

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜