66

I have a SportsCentre class which contains an array of Employee objects.

Which is the right way to show that an attribute's data type is an array of objects?

I have found two different versions online:

  • the first one uses the ArrayList<> keyword:

    SportsCentre
    - listOfRegistered : ArrayList<Employee>
    getRegisteredList() : ArrayList<Employee>
  • the second one uses square brackets []:

    SportsCentre
    - listOfRegistered : Employee[0..*]
    getRegisteredList() : Employee[0..*]
Yiannis
  • 929
  • 2
  • 11
  • 14

1 Answers1

41

Both are correct, but the second one, when multiplicity is set to more than one, is used more naturally, and it is not necessary to define the collection class as it is shown in the first picture of your example.

Simply said, multiplicity defines how many instances of a specific type can be stored by attribute. This set of instances can be ordered, or duplicates in it may be allowed. Parameters of multiplicity elements have an impact on the type of collection which should be used, Set, Vector, Array, etc.

But, if you need precise info about this issue, read UML Superstructure. Search for Property and Multiplicity Element. here is the UML website

Taufiq Rahman
  • 5,600
  • 2
  • 36
  • 44
Vladimir
  • 2,066
  • 15
  • 13
  • yes I do want to show the multiplicity, but it is also included on their association on the full diagram, that's why I considered the first option too. Thanks. – Yiannis Dec 13 '14 at 14:54