Objects and Classes - Types - Enumerations

11 important questions on Objects and Classes - Types - Enumerations

In Fig. 6.5, we show some sample enumerations.

Can you find them?



A common enumeration, that of TrafficLightColor is shown in both a US and UK style.

UML uses the VisibilityKind to identify the visibility of attributes and operations.

The EbookKind is a useful library domain enumeration for electronic books.

The standard name for the compartment showing the enumeration literals is “literals.”

What is the note attached to the VisibilityKind?

The note attached to the VisibilityKind indicates the standard symbols used in UML to identify the visibility of the feature.

In a class diagram, a member, i.e., an attribute or operation, would be preceded by one of the listed symbols to indicate the visibility

What is the VisibilityKind :  Public   +


The member value/behavior may be seen or invoked by anyone
  • Higher grades + faster learning
  • Never study anything twice
  • 100% sure, 100% understanding
Discover Study Smart

What is the VisibilityKind :  Private  -

The member is accessible only from within an instance of the class

What is the VisibilityKind :  Protected   #


Private, but instances of specializations of the class can also access

What is the VisibilityKind :  Package   ~

Private, but peer elements in the same package can also access

What is the VisibilityKind indicator?

The VisibilityKind indicator is an example of an adornment for attributes or operations.



In the UML specification, all the enumeration type names end with “Kind,” such as shown with VisibilityKind in Fig. 6.5.

We followed that reasonable convention with our own enumerations, but you may follow your own approach if you want.

In the figure, we included both TrafficLightColorKind and TrafficLightColourKind, to support both US and UK style traffic signals.

Enumeration literals have identity only within the...?

Enumeration literals have identity only within the enumeration.

Enumeration literals have identity only within the enumeration.

How can you test equality between two values?   

If you tried to test for equality between both the traffic light Green values, you may or may not get them to show as equal, or you might just receive a type error.

If you wish to refer to each color independently, you use the “.” naming scope operator, as shown below.

 

Enumerations can participate in generalizations.


Examine Fig. 6.6. How many literals does the
DirectionalTrafficLightColor have?

 

Six, as there are three inherited values (green, yellow, and red).

What is the internal representation of enumeration literals?

We do not worry about the internal representation of the enumeration literals.

They could be strings, integers starting with one, or integers starting with zero, or something else.

Some tools may allow you to specify values or an order to the literals for code generation, but that is not part of current UML.

The question on the page originate from the summary of the following study material:

  • A unique study and practice tool
  • Never study anything twice again
  • Get the grades you hope for
  • 100% sure, 100% understanding
Remember faster, study better. Scientifically proven.
Trustpilot Logo