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..*]

1 Answer

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

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest