Define the Notation for specifying Model Attributes
Notation for specifying Model Attributes in UML
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:
System of Objects
Objects do not exist in isolation, but as part of a larger system of objects that must interact with each other. The most fundamental relationship between objects is the has a relationship. The Java implementation of the Book class has three String attributes: title, author, and ISBN. String is a class, and the relationship between the Book class and the String class is illustrated in Figure 4-3.
The preceding figure is an example of a Booch class diagram. Grady Booch developed this notation for representing the relationships between the classes that comprise a software system. The simplest relationship is the has a relationship. The filled-in circle at one end of the connecting line indicates that it is the Book that has the String.
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.
Examples of Attribute Specifications
The structure of a class is represented by its attributes
Attributes may be found by examining class definitions, the problem requirements, business rules and by applying domain knowledge
The name, address and phone number for each person is needed before a reservation can be made.
These elements represent the attributes of a class. The following page discusses Discovering Attributes and how to identify ways to derive attributes and extend the sequence diagram to support Data access.
CompanyName : character = spaces {1 to 30 characters, spaces, and punctuation } InvoiceNumber : numeric { 12 digits } Temperature : numeric { 4 decimals of precision } Birthday : Date UnitPrice : numeric = 0 {2 decimals } SequenceNumber : integer = 0 { assigned sequentially by the system and unique } MailingAddress : Address = null
Attributes and Association have been unified in UML2
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 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.
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
In the next lesson, you will learn about operations.