Working with Object-Orientation and UML
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. You'll learn about
Visualizing a class
Responsibilities and constraints
Visualizing a Class
As I pointed out in the first hour, a rectangle is the icon that represents a class in the UML. 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).
Figure 3.1 The UML class icon.
Another UML construct, the package, can play a role in the name of a class. As I pointed out in Hour 1, "Introducing the UML," 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 whose name is a text string (see Figure 3.2).
Figure 3.2 A UML package.
If the WashingMachine class is part of a package called Household Appliances, you can give it the name Household appliances::WashingMachine. The double colons separate the package name on the left from the class name on the right. This type of class name is called a pathname (see Figure 3.3).
Figure 3.3 A class with a pathname.