Overview Of The Java Class Construct


The UML Class Diagram

Now that the three classes of the people manager project have been identified you can express their relationship to each other via a UML class diagram. The purpose of a UML class diagram is to express the static relationship between classes, interfaces, and other components of a software system. UML class diagrams are used to communicate and solidify your understanding of software designs to yourself, to other programmers, to management, and to clients. Figure 9-2 gives a basic UML diagram showing the static relationship between the classes identified in the people manager project.

image from book
Figure 9-2: Class Diagram for People Manager Classes

Each rectangle shown in figure 9-2 represents a class. The lines tipped with the hollow arrowheads represent generalization and specialization. The arrow points from the specialized class to the generalized class. This represents an “is a” relationship between the classes. As figure 9-2 illustrates, the classes Person, PeopleManager, and PeopleManagerApplication extend the functionality provided by the java.lang.Object. The Object class serves as the direct base class for all reference types that do not explicitly extend another class. (Inheritance is discussed in detail in chapter 11.)

Each class rectangle can be drawn as a simple rectangle or with three compartments. The uppermost compartment will have the class name, the middle compartment will list the fields, and the bottom compartment will list the methods.

Figure 9-2 further shows that the PeopleManagerApplication class is an application. It will have one method — main(). It could have fields and other methods since it is a Java class but in this example no other fields or methods are required.

The PeopleManagerApplication class uses the services of the PeopleManager class. This is indicated by the dashed arrow pointing from the PeopleManagerApplication class to the PeopleManager class. The dashed arrow represents a dependency. The PeopleManager class will have several attributes and methods which have yet to be defined.

The PeopleManager class will use the services of the Person class. The Person class will have attributes and methods as well. These will be developed in the next several sections.

The Person class uses the services of the java.util.Calendar class. The Calendar class will give the Person class the ability to calculate the age of each Person object.

Now that you have a basic design for the people manager project you can concentrate on one piece of the design and implement its functionality. Over the next several sections I will discuss the Java class construct in detail and show you how to create the Person and PeopleManager classes. Along the way I will show you how to test these classes using the PeopleManagerApplication class.

Quick Review

A Unified Modeling Language (UML) class diagram is used to show the static relationship between classes that participate in a software design. The class diagram is used to by programmers to express and clarify design concepts to themselves, to other programmers, to management, and to clients.

In UML a class is represented by a rectangle. The rectangle can have three compartments. The uppermost compartment contains the class name, the middle compartment contains fields, and the bottom compartment contains the methods.

Generalization and specialization is indicated with lines tipped with hollow arrows. The arrow points from the specialized class to the generalized class. The generalized class is the base class and the specialized class is the derived or subclass. Generalizations specify “is a” relationships between base and subclasses.

Dependencies are indicated by dashed arrows pointing to the class being depended upon. Dependencies are one way to indicate “uses” relationships between classes.




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

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