如何在Kotlin的UML类图中表示数组?

huangapple go评论75阅读模式
英文:

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&lt;String&gt; = Array(30) {&quot;&quot;}
  
  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&lt;String&gt;[30]
-grades: IntArray[30]

2.

-courses: Array&lt;String&gt;(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.

huangapple
  • 本文由 发表于 2023年7月13日 18:53:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76678567.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定