简体   繁体   English

类图:创建一个额外的类以集中现有系统中的信息吗?

[英]Class diagram: Create an extra class to concentrate information from an existing system?

I'm undecided as to what classes I could have that could adapt to an existing system which is an online video game. 我不确定我可以拥有哪些类以适应现有的在线视频游戏系统。 Here's what I want to achieve: 这是我要实现的目标:

  • Get a series of settings from objects in the server. 从服务器中的对象获取一系列设置。
  • Listen for clients to connect. 聆听客户端进行连接。
  • For each client, check that the settings on the client correspond with those from the server. 对于每个客户端,请检查客户端上的设置是否与服务器上的设置一致。
  • If settings don't correspond (something has been tampered with), either disconnect the client or change their settings. 如果设置不匹配(已被篡改),请断开客户端连接或更改其设置。

This will be handled by class that will act as an entry point and can serve as a form of controller. 这将由将作为入口点并可用作控制器形式的类进行处理。

Now, the settings are strewn accross a number of instances: players, weapons, flags, lights, etc. In procedural programming, I'd get all this information and store it an array. 现在,这些设置散布在许多实例中:玩家,武器,旗帜,灯光等。在过程编程中,我将获得所有这些信息并将其存储在一个数组中。 However, is there a better way of doing this according to an OO approach? 但是,根据OO方法是否有更好的方法呢? Can I make one or more classes that will have the values of these settings and act as a form of facade? 我可以制作一个或多个具有这些设置值并用作外观的类吗?

Encapsulate the settings data and behavior into at least one object (ie Settings ). 将设置数据和行为封装到至少一个对象(即Settings )中。 Depending on how your system is constructed this becomes part of other objects' composition (eg Player , Weapon , etc...), perhaps via dependency injection, or referenced from some global context. 根据系统的构造方式,这可能成为其他对象组成的一部分(例如PlayerWeapon等),可能是通过依赖注入或从某些全局上下文引用而来。 Settings is responsible for validation the match between client and server (eg Settings.validateClientServerSettingsMatch() ). Settings负责验证客户端和服务器之间的匹配(例如, Settings.validateClientServerSettingsMatch() )。 In terms of retrieving individual settings, two possible approaches explicit or implicit. 在检索单个设置方面,有两种可能的方法:显式或隐式。

Explicit 明确的

Your Settings object, or perhaps other entities that make its composition, have methods for each setting managed. 您的Settings对象,或者可能是其他组成其的实体,具有管理每个设置的方法。 So it could be something like Settings.getPlayerSettings().getSomeSetting() or 'Settings.getSomePlayerSetting()`. 因此可能是类似Settings.getPlayerSettings().getSomeSetting()或'Settings.getSomePlayerSetting()`之类的东西。 How nested really depends on your system. 嵌套的方式实际上取决于您的系统。 Either has the advantage of making clear what settings are available to the client development and it procides compile time type checking if you're using a language such as Java. 两种方法都有一个优势,即可以清楚了解哪些设置可用于客户端开发,并且如果使用的是Java之类的语言,则可以进行编译时类型检查。 The tradeoff is needing to alter an object every time a new setting comes into play. 每当新设置生效时,就需要权衡更改对象。

Implicit 隐含的

This just has a generic method in the Settings object - Settings.getSetting(settingName) . 这只是Settings对象中的一个通用方法Settings.getSetting(settingName) This makes it very easy to add settings, at the expense of any sort of useful type checking, unless you do something on your own using some meta magic of sorts in a language such as Python or Ruby or large case statements in Java. 这使得添加设置非常容易,而以任何有用的类型检查为代价,除非您使用某种语言(例如Python或Ruby或Java中的大写语句)使用某种元魔术来自己做某事。

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

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