Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to represent an attribute's data type as an array of objects on class diagram?

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..*]
like image 419
Yiannis Avatar asked Dec 13 '14 13:12

Yiannis


People also ask

How do you display an array in a class diagram?

You can show an array as an attribute with the size in brackets (just like in C++). Vectors can vary in size so you put an asterisk in the between the braces. You can also put these multiplicities on links between classes.

How do you show inheritance in a class diagram?

Inheritance is shown in a class diagram by using a solid line with a closed, hollow arrow. Bidirectional association: The default relationship between two classes. Both classes are aware of each other and their relationship with the other. This association is represented by a straight line between two classes.

How do you represent an object in a class diagram?

We use a rectangle to represent an object in an Object Diagram. An object is generally linked to other objects in an object diagram. For example – In the figure below, two objects of class Student are linked to an object of class College. Links – We use a link to represent a relationship between two objects.


1 Answers

Both are correct, but the second one, when multiplicity is set to more than one is used is more natural, and it is not necessary do define collection class as it is shown on the first picture of your example. Simply said, multiplicity defines how many instances of specific type can be stored by attribute. This set of instance can be ordered or duplicates in it may be allowed. Parameters of multiplicity element have impact on 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 UML website

like image 190
Vladimir Avatar answered Oct 21 '22 06:10

Vladimir