Terms and Concepts
A class is a description of a set of objects that share the same attributes, operations, relationships, and semantics. Graphically, a class is rendered as a rectangle.
Names
Every class must have a name that distinguishes it from other classes. A name is a textual string. That name alone is known as a simple name ; a qualified name is the class name prefixed by the name of the package in which that class lives. A class may be drawn showing only its name, as Figure 4-2 shows.
Figure 4-2. Simple and Qualified Names

A class name must be unique within its enclosing package, as discussed in Chapter 12 . |
Attributes
An attribute is a named property of a class that describes a range of values that instances of the property may hold. A class may have any number of attributes or no attributes at all. An attribute represents some property of the thing you are modeling that is shared by all objects of that class. For example, every wall has a height, width, and thickness; you might model your customers in such a way that each has a name, address, phone number, and date of birth. An attribute is therefore an abstraction of the kind of data or state an object of the class might encompass. At a given moment, an object of a class will have specific values for every one of its class's attributes. Graphically, attributes are listed in a compartment just below the class name. Attributes may be drawn showing only their names, as shown in Figure 4-3.
Figure 4-3. Attributes

Attributes are related to the semantics of aggregation, as discussed in Chapter 10 . |
Figure 4-4. Attributes and Their Class

You can specify other features of an attribute, such as marking it read-only or shared by all objects of the class, as discussed in Chapter 9 . |
Operations
An operation is the implementation of a service that can be requested from any object of the class to affect behavior. In other words, an operation is an abstraction of something you can do to an object that is shared by all objects of that class. A class may have any number of operations or no operations at all. For example, in a windowing library such as the one found in Java's awt package, all objects of the class Rectangle can be moved, resized, or queried for their properties. Often (but not always), invoking an operation on an object changes the object's data or state. Graphically, operations are listed in a compartment just below the class attributes. Operations may be drawn showing only their names, as in Figure 4-5.
Figure 4-5. Operations

You can further specify the implementation of an operation by using a note, as described in Chapter 6, or by using an activity diagram, as discussed in Chapter 20 . |
Figure 4-6. Operations and Their Signatures

You can specify other features of an operation, such as marking it polymorphic or constant, or specifying its visibility, as discussed in Chapter 9 . |
Organizing Attributes and Operations
When drawing a class, you don't have to show every attribute and every operation at once. In fact, in most cases, you can't (there are too many of them to put in one figure) and you probably shouldn't (only a subset of these attributes and operations are likely to be relevant to a specific view). For these reasons, you can elide a class, meaning that you can choose to show only some or none of a class's attributes and operations. You can indicate that there are more attributes or properties than shown by ending each list with an ellipsis ("..."). You can also suppress the compartment entirely, in which case you can't tell if there are any attributes or operations or how many there are.To better organize long lists of attributes and operations, you can also prefix each group with a descriptive category by using stereotypes, as shown in Figure 4-7.
Figure 4-7. Stereotypes for Class Features

Stereotypes are discussed in Chapter 6 . |
Responsibilities
A responsibility is a contract or an obligation of a class. When you create a class, you are making a statement that all objects of that class have the same kind of state and the same kind of behavior. At a more abstract level, these corresponding attributes and operations are just the features by which the class's responsibilities are carried out. A Wall class is responsible for knowing about height, width, and thickness; a FraudAgent class, as you might find in a credit card application, is responsible for processing orders and determining if they are legitimate, suspect, or fraudulent; a TemperatureSensor class is responsible for measuring temperature and raising an alarm if the temperature reaches a certain point.
Responsibilities are an example of a defined stereotype, as discussed in Chapter 6 . |
Modeling the semantics of a class is discussed in Chapter 9 . |
Figure 4-8. Responsibilities

You can also draw the responsibilities of a class in a note, as discussed in Chapter 6 . |
Other Characteristics
Attributes, operations, and responsibilities are the most common features you'll need when you create abstractions. In fact, for most models you build, the basic form of these three features will be all you need to convey the most important semantics of your classes. Sometimes, however, you'll need to visualize or specify other characteristics, such as the visibility of individual attributes and operations; language-specific features of an operation, such as whether it is polymorphic or constant; or even the exceptions that objects of the class might produce or handle. These and many other features can be expressed in the UML, but they are treated as advanced concepts.
Advanced class concepts are discussed in Chapter 9 . |
Interfaces are discussed in Chapter 11 . |
Internal structure is discussed in Chapter 15 . |
Active classes, components, and nodes are discussed in Chapters 23, 25, and 27, and artifacts are discussed in Chapter 26 . |
Class diagrams are discussed in Chapter 8 . |