user3215952
user3215952

Reputation: 233

How to define enumeration in uml object diagram

How can I define an enumeration in an object diagram?

+---------------------+
|   <<enumeration>>   |
|    :DayOfTheWeek    |
|    ¯¯¯¯¯¯¯¯¯¯¯¯¯    |
|_____________________|
| Sunday              |
| Monday              |
| Tuesday             |
| ...                 |
+---------------------+

or like that:

+---------------------------+
|      <<enumeration>>      |
|    Sunday:DayOfTheWeek    |
|    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯    |
|___________________________|
|                           |
+---------------------------+

+---------------------------+
|      <<enumeration>>      |
|    Monday:DayOfTheWeek    |
|    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯    |
|___________________________|
|                           |
+---------------------------+

I think it's only possible to create one instance of an enumeration object, is that right?

Upvotes: 0

Views: 3153

Answers (3)

qwerty_so
qwerty_so

Reputation: 36295

If you create an instance of your enumeration you can show the object state like this: enter image description here

Superstructures 2.1.1:

A name labeling the node indicates the type of the object node. The name can also be qualified by a state or states, which is to be written within brackets below the name of the type. Upper bounds, ordering, and control type other than the defaults are notated in braces underneath the object node.

Upvotes: 0

Jim L.
Jim L.

Reputation: 6529

An enumeration is a data type that has predefined enumeration literals, such as Sunday, Monday, and Tuesday. Every predefined enumeration literal is already an instance of its enumeration!

You can use an enumeration literal as a property value in some other object instance. For example, you might see a slot like dayOfWeek = Sunday inside an object instance of type CalendarEvent, assuming the CalendarEvent type defines a dayOfWeek property of type DayOfTheWeek.

BTW, a class diagram can show both classes and instances. I don't think there is such a thing as an "instance diagram" in UML 2, that is just the colloquial name for instances on a class diagram.

Upvotes: 0

SomeWittyUsername
SomeWittyUsername

Reputation: 18338

It's important to distinguish between class and object diagrams. If you were talking about class diagram, indeed there was only one class of your DayOfTheWeek type, but there is no restrictions on the number of enumeration objects (unless you defined it explicitly as singleton). E.g., one enumeration object can represent Sunday and the other one can represent Friday.

Upvotes: -1

Related Questions