如何在UML中为不同类型的字段和实体连接建模 [英] How to modelling different types of fields and entities connection in UML

查看:73
本文介绍了如何在UML中为不同类型的字段和实体连接建模的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任务:

  • 每个字段都有多个实体的位置,并具有1-10个邻居.字段是不同的.其中一些被困,如果一个实体踩他们,他们将无法离开.也有放射性场,如果一个实体在这些场上花费太多时间,他们死了.不能同时捕获和放射性场.
  • 有两个不同的实体.其中一些能够逃脱被困的野外(E1),而另一些则对放射免疫(E2)免疫.实体可以在相邻的图块之间移动.

由此我得到以下类图(仅是类):

From this I have got the following class diagram (only the classes):

所以我想知道如果 E1 踩在 Radioactive 上并且如果停留太久就会死去,该如何表示呢?此外,当新的 E1 出现而第一个没有出现时,它如何处理呢?

So I want to know how can I represent that if E1 steps on Radioactive and if it stays there too long dies? Furthermore how can it handle that case when a new E1 comes and it does not die when the first one?

首先我尝试了类似的方法,但是它无法处理该事件

First I tried with something like this, but it can not handle that event

我的话

推荐答案

第一个图表(问题的第一个版本)

First diagram (first version on the question)

您的概括(如果存在)指向错误的方向,当前 Field Trapped Radioactive Entity E1 E2 ,但是您想要相反的操作.

Your generalizations if they exist are in the wrong direction, currently a Field is a Trapped and a Radioactive and an Entity is a E1 and a E2, but you wanted the reverse.

无论如何,在声明中没有任何内容表明字段不能同时被捕获和具有放射性,而不是为了更好地使用归纳法来使用属性.

Anyway there is nothing in the statement saying a field cannot be both trapped and radioactive, in that case rather than to use generalizations better to use properties.

对于实体来说,似乎只有 E1 E2 ,因此您可以使用归纳(反方向)

For the Entities it seems there are only E1 and E2 so you can use generalization (in reverse direction)

第二张图

请注意,如果 Radioactive 实现了 Timer ,这意味着其他人必须踢出每个 Radioactive ,只有他们(没有其他 Field ).

Note if Radioactive implements a Timer that means someone else has to kick each Radioactive and only them (no other Field).

关于死亡时间,无论 E1 Radioactive 实例是否相同,该属性都可以是静态的.

Concerning the time to die, if it is the same whatever the instance of E1 and Radioactive that attribute can be static.

我不了解 KillEntity 操作,因为杀死 E1 的时间取决于每个实例进入字段的时间,因此不能通用

I do not understand the operation KillEntity because the moment an E1 is killed depends on when each instance enter in the field so cannot be general

您至少可以处理 Radioactive 中的 Field 死亡的延迟,例如:

You can handle the delay to die for a Field in a Radioactive in that least, for instance :

  • 每次实体输入放射性实体就会添加到 dying 中,例如将持续时间初始化为0
  • 每次放射性核素中的 Entity 出口时, dying
  • 中的 Entity 都会被移除.
  • 每次调用 tick 时,每个持续时间都会增加,当变为 timeToDie 时,将从 dying 中删除相应的实体,并进行操作死了呼吁
  • dies 操作在 Entity 上没有显示,但是在 E2 上指示该实例已被杀死(也可以将该操作抽象为实体,并且已定义,但对 E1 没有任何作用)
  • each time an Entity enter in a Radioactive the Entity is added in dying for instance initializing duration to 0
  • each time an Entity exit in a Radioactive the Entity is removed in dying
  • each time tick is called each duration is increased and when becoming timeToDie the corresponding Entity is removed from dying and the operation die called on it
  • the operation dies does noting on Entity but on E2 indicates the instance is killed (it is also possible to have that operation abstract on Entity and defined but doing nothing on E1)

请注意,您可以将类关联替换为带有评估持续时间等的限定符

Note you can replace the class-association by an association with a qualifier valuing the duration etc

但是您也可以处理在 E2 中死亡的延迟:

But you can also handle the delay to die in E2 :

    每次 Entity/E2 上的
  • tick 都由 radioactive 在其 Fields 上应用本身被打勾, tick Entity 不执行任何操作,但管理 E2 上的持续时间以在所需的延迟后终止实例(可以将静态属性设置为再次显示)

  • tick on Entity/E2 is applied by a Radioactive on its Fields each time it is itself ticked, tick does nothing on Entity but manages the duration on E2 to kill the instance after the required delay (a static attribute can be shown again)

每次 E2 移至新的 Field 时,持续时间将重置为0

each time an E2 moves to a new Field the duration is reset to 0

请注意,您的多重性 1 .. * 是错误的,因为 Field 可能没有 Entity ;相反,如果多重性为1,死掉的 E2 留在放射性中,否则 0..1

Note your multiplicity 1..* is wrong because a Field may not have Entity, on the opposite side the multiplicity is 1 if a dead E2 stay in a Radioactive else 0..1

这篇关于如何在UML中为不同类型的字段和实体连接建模的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆