The Structure of a Class Diagram

 <  Day Day Up  >  

A class diagram is constructed of three different parts : the class name , the attributes, and the methods (constructors are considered methods). The class diagram is essentially a rectangle that separates these three parts with horizontal lines. The book often uses a cabbie metaphor as an illustration. Figure 10.1 shows the UML class diagram representing this class.

Figure 10.1. A UML diagram of the Cabbie class.

graphics/10fig01.gif

This UML diagram corresponds exactly to the following Java code:

 
 /*     This class defines a cabbie and assigns a cab */ public class Cabbie {     // Place the name of the company here     private static String companyName = "Blue Cab Company";     // Name of the cabbie     private String name;     // Car assigned to cabbie     // Default constructor for the cabbie     public Cabbie() {         name = null;         myCab = null;     }     // Initializing the constructor for the cabbie     public Cabbie(String iName, String serialNumber) {         Name = iName;         myCab = new Cab(serialNumber);     }     // Set the name of the cabbie     public void setName(String iName) {         name = iName;     }     // Get the name of the cabbie     public String getName() {         return name;     }     // Give the cabbie directions     public void giveDirections(){     }     // Cabbie turns right     private void turnRight(){     }     // Cabbie turns left     private void turnLeft() {     }     // Get the name of the company     public static String getCompanyName() {         return companyName;     } } 

Take a moment to look at the code and compare it to the UML class diagram. Notice how the class name, attributes, and methods in the code relate to the designation in the class diagram. Really, that is all there is to the class diagram as far as the structure goes. However, there is a lot more information to be gleaned from the diagram. This information is discussed in the following sections.

 <  Day Day Up  >  


Object-Oriented Thought Process
Object-Oriented Thought Process, The (3rd Edition)
ISBN: 0672330164
EAN: 2147483647
Year: 2003
Pages: 164
Authors: Matt Weisfeld

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net