Static List of all Objects of Class

徘徊边缘 提交于 2020-01-06 04:32:12

问题


I wanted to implement a static List for my Class which contains all Objects of the Class like in the following UML approach.

Is this the right way to write the UML?

There is also a question which uses this UML if you know Kotlin i would be happy if you can help me there too ;) Static List of Objects out Class in Kotlin


回答1:


This is almost correct. Instead of List<IMyClass> the regular UML notation is IMyClass[*].

The UML 2.5.1 specification, section 9.5.4 gives the following notation syntax for a property:

<property> ::= [<visibility>] [‘/’] <name> [‘:’ <prop-type>] [‘[‘ <multiplicity-range> ‘]’] [‘=’ <default>] [‘{‘<prop-modifier > [‘,’ <prop-modifier >]* ’}’]

In your case, the prop-type is IMyClass and the multiplicity-range is *.




回答2:


Use the stereotype to specify you use a list, for instance :

or if you prefer :

Note : are you sure you want it public ? this is dangerous


Edit for the remark of @qwerty_so: it does not make sense to stereotype an association with <<list>> where you place a multiplicity which makes it a "list" already. Looks like an over-definition too me

The multiplicity indicates a collection, and there are four types of collection depending on isOrdered and isUnique properties (c.f. formal-17-12-05 §7.5.3.2 Multiplicities, Table 7.1 Collection types for MultiplicityElements, page 34) :

isOrdered  | isUnique | Collection Type
-----------+----------+-----------------
   false   |   true   |      Set
    true   |   true   |   OrderedSet
   false   |  false   |      Bag
    true   |  false   |    Sequence

Furthermore a list is one of the subtypes of Sequence, so the multiplicity "*" is far from indicating a "list" already.



来源:https://stackoverflow.com/questions/56592278/static-list-of-all-objects-of-class

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!