0

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?

user3215952
  • 223
  • 5
  • 11
  • There's no such kind of diagram in UML 2. Instance specifications are shown on class diagrams. – Jim L. May 25 '15 at 04:57

3 Answers3

0

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.

Jim L.
  • 6,177
  • 3
  • 21
  • 47
  • "Every predefined enumeration literal is already an instance of its enumeration!" - any reference to back this up? – SomeWittyUsername May 15 '15 at 06:15
  • 1
    From the UML 2.5 spec: "An Enumeration is a DataType whose values are enumerated in the model as EnumerationLiterals," "An EnumerationLiteral is a user-defined data value for an Enumeration," "Generalizations InstanceSpecification," and "An InstanceSpecification is a model element that represents an instance in a modeled system." If you look in the repository after creating an enumeration literal in a conformant tool, you will find that he classifier of an EnumerationLiteral is its owning Enumeration. – Jim L. May 21 '15 at 21:07
  • Seconded. Valid answer. – Pétur Ingi Egilsson Dec 23 '16 at 22:14
0

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.

qwerty_so
  • 35,448
  • 8
  • 62
  • 86
  • Your explanation is correct for class diagram, while the user explicitly asked for object diagram – SomeWittyUsername May 15 '15 at 11:31
  • @icepack Oh thanks. I overlooked that. Will correct my answer. – qwerty_so May 15 '15 at 12:23
  • To my knowledge, an object in a state is not possible on a class diagram. It is possible on an activity diagram. – Jim L. May 25 '15 at 04:53
  • The OP talks about OD: "enumeration in an object diagram". The "state" used in Superstructures refers to one possible representation of an enumeration. Alas, there is no limitation (at least up to 2.4) which element can be put into which diagram. – qwerty_so May 25 '15 at 09:07
-1

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.

SomeWittyUsername
  • 18,025
  • 3
  • 42
  • 85
  • There are no instance diagrams in UML 2. – Jim L. May 25 '15 at 04:55
  • @JimL. True, but the user specifically asks about it. No one forces him to use the latest UML spec (or UML at all for that matter) – SomeWittyUsername May 25 '15 at 06:33
  • The poster doesn't specify the version, but does tag the question as UML. Does it make sense to provide answers nearly 15 years out of date? That wouldn't fly with Java or any other language. – Jim L. May 25 '15 at 10:52