简体   繁体   English

这种设计有名称吗?

[英]Is there a name for this type of design?

So I am writing a game (c#, xna), and was just wondering if there is a name for what I am doing. 所以我正在写一个游戏(c#,xna),只是想知道我在做什么而已。

This isn't necessarily specific to Game Programming, or my game. 这不一定特定于游戏编程或我的游戏。 But programming and encapsulation in general. 但是一般来说编程和封装。

Essentially I have two game objects, one (Chute) is dependent on the data of another (the list of Blueprints in BlueprintManager). 本质上,我有两个游戏对象,一个(滑道)依赖于另一个游戏对象(BlueprintManager中的蓝图列表)的数据。 I don't want to expose the BlueprintManagers list of Blueprints to the outside world. 我不想向外界公开Blueprints的BlueprintManagers列表。 However Chute needs to know them to operate. 但是,滑道需要了解它们的操作。

So instead of exposing the list of Blueprints, I created a method in BlueprintManager which accepts a Chute, and in that method "gives" it's Blueprints to the Chute. 因此,我没有公开蓝图的列表,而是在BlueprintManager中创建了一个接受滑槽的方法,并在该方法中“将”蓝图提供给了滑槽。

Now I am wondering if this is an effective way to maintain the encapsulation of my data. 现在,我想知道这是否是维护数据封装的有效方法。 Also I am wondering if there is a name for this type of method/design. 我也想知道这种方法/设计是否有名称。 Any best practices for this? 有什么最佳实践吗?

This code is in BlueprintManager which has the list of Blueprints which Chute needs. 此代码在BlueprintManager中,该文件具有Chute所需的蓝图列表。

        public void GiveChuteBlueprints(Chute chute)
        {
            chute.AcceptBlueprints(this._acitveBlueprints);
        }

在我看来,这就像“ 访客”模式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM