我们可以在UML类图中的一行上声明多个变量吗?

时间:2014-12-15 03:25:52

标签: uml

private int x1, x2, y1, y2;

UML行可以是:

- x1,x2,y1,y2: int

或者我们是否必须在4个单独的线上制作它们?

2 个答案:

答案 0 :(得分:4)

您指的是UML类图。

这意味着你不是指变量。您指的是属性

UML类图不包含“行”。它们是UML类模型的图形描述。该模型包括属性列表。类图显示了属性集。

我从未见过UML的实现,它在类图的同一行上显示多个属性。

答案 1 :(得分:1)

UML标准包含所有明显不同类型属性的示例。如您所见,一行中不可能有多个属性。

enter image description here

ClassA::name is an attribute with type String.
ClassA::shape is an attribute with type Rectangle.
ClassA::size is a public attribute of type Integer with multiplicity 0..1.
ClassA::area is a derived attribute with type Integer. It is marked as read-only.
ClassA::height is an attribute of type Integer with a default initial value of 5.
ClassA::width is an attribute of type Integer.
ClassB::id is an attribute that redefines ClassA::name.
ClassB::shape is an attribute that redefines ClassA::shape. It has type Square, a specialization of Rectangle.
ClassB shows size as an attribute inherited from ClassA, as signified by the prepended caret symbol (see 9.2.4).
ClassB::height is an attribute that redefines ClassA::height. It has a default of 7 for ClassB instances that overrides the ClassA default of 5.
ClassB::width is a derived attribute that redefines ClassA::width, which is not derived.

http://www.omg.org/spec/UML/2.5/Beta2/ - 我强烈建议使用2.5版本,即使它是beta2版本。对于内容(正式),我与接受的2.4.1绝对相同,但在解释方式上有所不同 - 更容易。