Logical View  «Prev  Next»
Lesson 3 Modeling attributes
Objective 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.

Attribute visibility

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:

AMP Image 1
  1. Derived attribute indicator: Optional
  2. Attribute name: Required
  3. Data type: Required
  4. Assignment operator and default value: Optional
  5. Constraints: Optional
  6. Visibility: Required before code generation
  7. Class attribute: Optional
Attribute definitions
Modeling Attribute Dissection
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.

Attribute definitions

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 Attribute Name

In a UML class diagram, you can add attributes to classes and interfaces. An attribute defines values that can be attached to instances of the class or interface.

Attributes and Association have been unified in UML2

Attributes and association ends have been semantically unified in UML2, so that it is much easier to convert among them in a model. The multiplicity setting now appears after the type name, rather than after the attribute name. This makes it possible to treat the multiplicity as part of the overall type specification. Redefinition and subsetting have been added. The concept of target scope has been dropped.

1) Create an attribute name
Create an attribute name

2) Define the data type
Define the data type

3) Define the default value
Define the default value

4) Set the constraints on the data values
companyname:character=spaces
(1 to 30 characters)
Set the constraints on the data values. First identify the field length.
  1. Create an attribute name
  2. Define the data type
  3. Define the default value
  4. Set the constraints on the data values. First identify the field length.
  5. Next identify the types of data that can be used in the field
  6. 1 to 30 characters, including alphabetic, spaces, and punctuation characters, no special characters allowed


5) Identify tye types of data that can be used in the field
Next identify the types of data that can be used in the field

6) Set the attribute visibility
-companyname: character = spaces 

{ 1 to 30 characters, including alphabetic, spaces, and punctuation characters, no special characters allowed}
Set the attribute visibility

In the next lesson, you will learn about operations.

Modeling Attribute Notations - Quiz

Click the quiz link below to take a short multiple-choice quiz on modeling attributes.
Modeling Attribute Notations - Quiz