gpt4 book ai didi

c++ - OOP - 在类之间共享数据

转载 作者:行者123 更新时间:2023-11-28 04:54:55 26 4
gpt4 key购买 nike

<分区>

我有一个保存数据并公开访问该数据的方法的类:GameInfoList。数据是基于 3 个接口(interface)创建的:A、B、C。我还有 2 个接口(interface)来获取特定数据:D、E。

我需要在两个类之间共享 GameInfoList,这是我的方法:

//fills GameInfoList based on interfaces called by the different clients.
class GameInfo: public A, public B, public C
{
public:
GameInfo(GameInfoList&)
//A,B,C impl
private:
GameInfoList& gameInfoList;
};

//reads GameInfoList and allow to get a particular info.
class GameInfoProvider: public D, public E
{
public:
GameInfoProvider(const GameInfoProvider&)
//D,E impl
private:
const GameInfoList& gameInfoList;
};

是否有引用上述场景的设计模式?您如何看待我的方法?

编辑GameInfoList、GameInfo 和 GameInfoProvider 对象存在于“Component”类中,因此生命周期清晰。组件之间的通信基于 Thrift 。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com