如何在 UML class 图上显示用户作为参数提供的对象?
How to show an object provided as an argument by a user on a UML class diagram?
我有一个 JavaScript 函数,它应该像 class 一样工作,它需要来自用户的几条数据。
我决定让它期望一个对象以这些数据片段作为参数,例如:
new ClassFunction({
arg_1: 'foo',
arg_2: 'bar'
});
在 UML class 图上显示它的最佳方式是什么?
我应该把它写成花括号中的注释还是作为单独的注释或抽象 class 以及从构造函数 class (ClassFunction) 到那个抽象 class?
或者可能是别的东西?
JavaScript function, which is supposed to act like a class
更恰当的说法是对象构造函数;这也可以让您更好地了解您实际想要做什么。
现在提供给构造函数的参数是一些匿名的 class,可以理解 arg_1
和 arg_2
。 UML 通过 DataType
s 对此进行建模,用 <<dataType>>
关键字表示。
A DataType is a kind of Classifier. DataType differs from Class in that instances of a DataType are identified only by their value. All instances of a DataType with the same value are considered to be equal instances. [UML Spec 10.2]
例如,您的案例可以建模如下:
我有一个 JavaScript 函数,它应该像 class 一样工作,它需要来自用户的几条数据。
我决定让它期望一个对象以这些数据片段作为参数,例如:
new ClassFunction({
arg_1: 'foo',
arg_2: 'bar'
});
在 UML class 图上显示它的最佳方式是什么?
我应该把它写成花括号中的注释还是作为单独的注释或抽象 class 以及从构造函数 class (ClassFunction) 到那个抽象 class?
或者可能是别的东西?
JavaScript function, which is supposed to act like a class
更恰当的说法是对象构造函数;这也可以让您更好地了解您实际想要做什么。
现在提供给构造函数的参数是一些匿名的 class,可以理解 arg_1
和 arg_2
。 UML 通过 DataType
s 对此进行建模,用 <<dataType>>
关键字表示。
A DataType is a kind of Classifier. DataType differs from Class in that instances of a DataType are identified only by their value. All instances of a DataType with the same value are considered to be equal instances. [UML Spec 10.2]
例如,您的案例可以建模如下: