mercredi 18 mai 2016

How to share an instance among several classes in c++, not using Singleton pattern

Now I'm developing a c++ application and I'm facing a problem of sharing an instance.

For this problem, I created a simple class diagram. I want to share HogeDataManager for class A and C. A creates HogeDataManager and read HogeData via its public methods. And B adds some data to HogeDataManager.

For sharing HogeDataManager, I have to prepare set_mgr method for B and C. But I think it is not a smart way. Of course if I adopt Singleton pattern, it will be resolved. But Singleton is sometimes dangerous, so I want to find better ways to avoid such a problem.

enter image description here

Aucun commentaire:

Enregistrer un commentaire