Looking for a better C++ class factory

前端 未结 10 741
伪装坚强ぢ
伪装坚强ぢ 2020-12-29 00:40

I have an application that has several objects (about 50 so far, but growing). There is only one instance of each of these objects in the app and these instances get shared

10条回答
  •  猫巷女王i
    2020-12-29 01:12

    Instead of GetInterfaceId() in the BrokeredObject base class, you could define that pure virtual method:

    virtual BrokeredObject& GetInstance()=0;
    

    And in the derived classes you'll return from that method the instance of the particular derived class, if it's already created, if not, you'll first create it and then return it.

提交回复
热议问题