- Visualizing a Class
- Attributes
- Operations
- Attributes, Operations, and Visualization
- Responsibilities and Constraints
- Attached Notes
- Classes—What They Do and How to Find Them
- Summary
- Q&A
- Workshop
Responsibilities and Constraints
The class icon enables you to specify still another type of information about a class. In an area below the operations list, you can show the class's responsibility. The responsibility is a description of what the class has to dothat is, what its attributes and operations are trying to accomplish. A washing machine, for example, has the responsibility of taking dirty clothes as input and producing clean clothes as output.
In the icon, you indicate responsibilities in an area below the area that contains the operations (see Figure 3.12).
Figure 3.12 In a class icon, you can write the class's responsibilities in an area below the operations list area.
The idea here is to include enough information to describe a class in an unambiguous way. Indicating the class's responsibilities is an informal way to eliminate ambiguity.
A slightly more formal way is to add a constraint, a free-form text enclosed in curly brackets. The bracketed text specifies one or more rules the class follows. For example, suppose in the WashingMachine class you wanted to specify that the capacity of a washer can be only 16, 18, or 20 pounds (and thus "constrain" the WashingMachine class's capacity attribute). You would write {capacity = 16 or 18 or 20 lbs} near the WashingMachine class icon. Figure 3.13 shows how to do it.
Figure 3.13 The rule in curly brackets constrains the capacity attribute to be one of three possible values.
More on Constraints
The UML works with still anotherand much more formalway of adding constraints that make definitions more explicit. It's an entire language called Object Constraint Language (OCL). An advanced and sometimes useful tool, OCL has its own set of rules, terms, and operators. The Web site of the Object Management Group (http://www.omg.org) provides documentation on OCL.