Working with Object-Orientation in UML
What You'll Learn in This Hour:
- How to model a class
- How to show a class's features, responsibilities, and constraints
- How to discover classes
Now it's time to put the UML together with the object-oriented concepts you learned in the last hour. In this hour, you'll firm up your knowledge of object-orientation as you learn more about the UML.
Visualizing a Class
As I pointed out in the first hour, a rectangle is the icon that represents a class in the UML. From Hours 1, "Introducing the UML," and 2, "Understanding Object-Orientation," recall that the name of the class is, by convention, a word with an initial uppercase letter. It appears near the top of the rectangle. If your class has a two-word name, join the two words together and capitalize the first letter of the second word (as in WashingMachine in Figure 3.1).
Another UML construct, the package, can play a role in the name of a class. As I pointed out in Hour 1, a package is the UML's way of organizing a diagram's elements. As you might recall, the UML represents a package as a tabbed folder. The package's name is a text string (see Figure 3.2).
Figure 3.1 The UML class icon.
Figure 3.2 A UML package.
If the WashingMachine class is part of a package called Household, you can give it the name Household::WashingMachine. The double colons separate the package name on the left from the classname on the right. This type of classname is called a pathname (see Figure 3.3).
Figure 3.3 A class with a pathname.