在绘制UML时使用属性(属性),而不是一个协会/汇聚/成分 [英] When to use an attribute (property) instead of an association/aggregation/composition when drawing a UML

查看:79
本文介绍了在绘制UML时使用属性(属性),而不是一个协会/汇聚/成分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以我有点困惑,我要一个属性添加到一个类VS试图显示UML图的关系时,绘制关联的一类。

Okay so I'm a bit confused as to when I should add an attribute to a class vs drawing an association to a class when trying to show a relationship in a UML diagram.

例如假设我有一个包含10状态的对象各有一组不同的在DFA路径的各种状态的DFA类。我方应该吸取做出DFA组成行至国类或只需键入的所有10个州的DFA类的属性部分。

For example let's say I have a DFA class that contains 10 state objects each having a different set of paths to various states in the DFA. Should I draw the composition line from the DFA to the State class or just type all 10 states in the attribute section of the DFA class.

基本上我想他们之间计算出,如果当一个类中包含(或由)一个或多个类烧烤,我应该画一条线(聚合,组成,协会的依赖等),或者只是把一个作为一个属性到另一个地方。

Basically I'm trying to figure out if when a Class A contains (or is composed of) one or more Class Bs, should I draw a line (aggregation, composition,association dependency etc) between them or just put one as an attribute to another.

本文试图回答这个问题,但我感到困惑,当他开始谈论他提请图表。

This article attempts to answer the question but I get confused as soon as he starts talking about the diagrams he drew.

推荐答案

您指出的文章给出了一个指引:

The article you pointed gives one guideline:

在我一直在使用不同的建模团队这些年来我发现,效果最好的规则是使用关联类和属性的数据类型。
  数据类型是一种特殊的分级的,类似于类。它不同于在数据类型的该实例的类是由它们的值仅鉴定

In the years I’ve been working with different modelling teams I’ve found that the rule that works best is to use Associations for Classes and Attributes for DataTypes. A data type is a special kind of classifier, similar to a class. It differs from a class in that instances of a data type are identified only by their value.

我与作者那种同意,加入另一点:你的类图应该理解。如果你有一个图有许多纵横交错线相互图是没用的。发生这种情况时,你必须设法找到可以使用属性不失去太多的视觉信息进行建模的关系,并与属性替换它们。

I kind of agree with the author, adding another point: your class diagram should be understandable. If you have a diagram with many lines crisscrossing each other the diagram is useless. When this happens you must try to find relations that can be modeled using attributes without loosing too much visual information, and replace them with attributes.

您可以用关系​​,而不是与属性做的另一件事是显示双向关系(您可以在每个类关系的一个属性做到这一点,但你失去关系的语义)。

Another thing that you can do with relations and not with attributes is to display bi-directional relations (you can do this with one attribute in each class of the relation, but you loose the semantics of the relation).

这篇关于在绘制UML时使用属性(属性),而不是一个协会/汇聚/成分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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