An attribute is a property of a class. It describes a range of values that the property may hold in objects (that is, in instances) of that class. A class may have zero or more attributes. By convention, a one-word attribute name is written in lowercase letters. If the name consists of more than one word, the words are joined and each word other than the first word begins with an uppercase letter. The list of attribute names begins below a line separating them from the classname, as Figure 3.4 shows.
Figure 3.4 A class and its attributes.
Every object of the class has a specific value for every attribute. Figure 3.5 presents an example. Note that an object's name begins with a lowercase letter, precedes a colon that precedes the classname, and the whole name is underlined.
Naming Objects . . . or Not
The name myWasher:WashingMachine is a named instance. It's also possible to have an anonymous instance like :WashingMachine.
Figure 3.5 An object has a specific value for every one of its class's attributes.
The UML gives you the option of indicating additional information for attributes. In the icon for the class, you can specify a type for each attribute's value. Possible types include string, floating-point number, integer, and Boolean (and other enumerated types). To indicate a type, use a colon to separate the attribute name from the type. You can also indicate a default value for an attribute. Figure 3.6 shows these ways of specifying attributes.
Figure 3.6 An attribute can show its type as well as a default value.
An enumerated type is a data type defined by a list of named values. Boolean, for instance, is an enumerated type because it consists of the values "true" and "false." You can define your own enumerated types like State, which consists of the values "solid," "liquid," and "gas."