Define the Notation for specifying Model Attributes
Notation for specifying Model Attributes
What is an UML Attribute?
An attribute describes a piece of information that an object owns or knows about itself. To use that information we must assign a label and a name, and then specify the kind of information, or data type.
Data types may be primitive data types supplied by a language or abstract data types defined by the developer. In addition, each attribute may have rules constraining the values assigned to it.
Often a default value is set when no rule is provided.
Each attribute definition must also specify what objects are allowed to see the attribute, that is its "visibility."
Visibility is defined as public (+) for elements of a class that are visible to all other classes. Private (-) visibility limits access to the element to within the class itself.
For example, only operations of the class have access to a private attribute. In the case of generalizations (inheritance), subclasses must have access to the attributes and operations of the superclass or they cannot be inherited.
So generalizations use a protected (#) visibility. Given these requirements, the following notation is used to define an attribute:
The slash mark is optional and denotes a derived attribute.
The dollar sign indicates a class-level element, for example, a single instance of the element shared by all objects of the class.
The constraint notation brackets appear throughout UML diagrams to identify any and all additional information that helps clarify the intent of the modeling element. Place any text required to explain the limitations imposed on the implementation of the modeling element in the constraint brackets.
Let's create an example attribute definition for a company name. The field has to handle characters and punctuation marks commonly found in company names, but we are limited to 30 positions. There is a no default value, but we want valid display data, so we must initialize the field to spaces.
Create an attribute name
Define the data type
Define the default value
Set the constraints on the data values. First identify the field length.
Next identify the types of data that can be used in the field
1 to 30 characters, including alphabetic, spaces, and punctuation characters, no special characters allowed