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..*] |
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With