Search code examples
umlrelationshipcustom-data-typemultiplicity

UML: Self-defined data types as attributes in classes / when adding an attribute to a class is allowed


Similar questions have been asked, but this does not fully address my problem:

I am having problem with the following statement made by my teacher:

  1. "You can only have in-built or custom-defined data types, as types of attributes in your classes. For other attributes multiplicity defines quantity and whether it is obligatory." (fair enough)

Let's assume the following description:

[...]Each operation holds a sequence of tasks to be executed on a required quality level - for each task there is an associated quality level selected from the list of available quality levels for this task.[...] (Operation holds number of other attributes as well).

Now I have drawn the following "class diagram": class diagram

Questions:

  1. Can I have self-defined data types as part of my class diagram (as a class) or can these be used only as attributes within other classes?

  2. If these data types can be used only as attributes, then I do not know how I can mark the fact that the collection is ordered and unique other by adding this attribute to a class - which - according to my teacher - is not allowed - because then I would be having a collection of a type which is neither an in-built type or self-defined type as an attribute.

  3. According to my knowledge adding an attribute to a class and specifying this collection is ordered is the only way of marking such property and cannot be achieved with multiplicity.

Can someone please shed a bit of light on what is the proper notation?


Solution

    1. You can have as many self defined Datatype on your diagram as you want, but beware: there's a difference between Datatype and a Class

    2. UML allows to use both Classes and Datatypes to be the type of your Attribute.

    3. In UML Attributes and Associations are often interchangeable. The defining characteristics of both are defined in Property, which includes multiplicity and other constraints such as {ordered}

    However there are best practices in use that your teacher may be referring too. It is quite sensible to use attributes for relations to Datatypes and associations for relations to Classes. For more information about this see UML Best Practice: Attribute or Association