英文:
How to represent an array in UML class diagram for Kotlin?
问题
-courses: Array<String>[30]
-grades: IntArray[30]
英文:
I have the following Kotlin class:
class Student {
private val courses: Array<String> = Array(30) {""}
private val grades: IntArray = IntArray(30)
}
I am trying to create a UML class diagram for this Kotlin class. I am confused about the way to model the array attributes courses and grades.
Which of these UML representations is correct?
1.
-courses: Array<String>[30]
-grades: IntArray[30]
2.
-courses: Array<String>(30)
-grades: IntArray(30)
3.
-courses: String[30]
-grades: Int[30]
答案1
得分: 3
在UML中,没有数组的概念。相反,有具有多重性的属性。通过这个,你可以指定允许的元素数量以及它们的排序和唯一性。数组定义了一个顺序,但不要求其中的元素是唯一的。因此,它将被指定为:
property1:Integer[10..30]{ordered, non unique}
。
这将显示在类的属性区域中。
如何将这个转化为编程语言的文本表示取决于代码生成器,不应该是建模者关心的问题。
当然,定义你的编程语言的特定原始数据类型可能是有意义的,这样图表的读者可以看到熟悉的类型。或者,你可以定义一个从预定义的UML原始类型到编程语言类型的映射。
英文:
In UML there is no concept of an array. Instead there are properties that have a multiplicity. With this you can specify the number of allowed elements and their ordering and uniqueness. An array defines an ordering, but doesn't require the elements in it to be unique. So it will be specified like this:
property1:Integer[10..30]{ordered, non unique}
.
This would be shown in the attributes compartment of a class.
How this is translated into a textual notation of a programming language is up to the code generator and should be of no concern to the modeler.
Of course, it might make sense to define the specific primitive datatypes of your programming language, so that readers of the diagram see familiar types. Alternatively you can define a mapping from the predefined UML primitive types.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论