Java Reference
In-Depth Information
RollingDice
Die
faceValue : int
roll() : int
setFaceValue (int value) : void
getFaceValue() : int
toString() : String
main (args: String [] ) : void
FIGURE 4.4 A UML class diagram showing the classes involved in the
RollingDice program
In a UML diagram, each class is represented as a rectangle, pos-
sibly containing three sections to show the class name, its attributes
(data), and its operations (methods). Figure 4.4 shows a class dia-
gram containing the classes of the RollingDice program.
The arrow connecting the RollingDice and Die classes in
Figure 4.4 indicates that a relationship exists between the classes. A
dotted arrow indicates that one class uses the methods of the other class. Other
types of object-oriented relationships between classes are shown with different types
of connecting lines and arrows. We'll discuss these other relationships as we explore
the appropriate topics in the topic.
Keep in mind that UML is not designed specifically for Java programmers.
It is intended to be language independent. Therefore the syntax used in a UML
diagram is not necessarily the same as Java. For example, the type of a variable
is shown after the variable name, separated by a colon. Return types of methods
are shown the same way.
UML diagrams are versatile. We can include whatever appropriate information
is desired, depending on the goal of a particular diagram. We might leave out the
data and method sections of a class, for instance, if those details aren't relevant
for a particular diagram.
UML diagrams allow you to visualize a program's design. As our programs get
larger, made up of more and more classes, these visualizations become increasingly
helpful. We will explore new aspects of UML diagrams as the situation dictates.
KEY CONCEPT
A UML class diagram helps us visual-
ize the contents of and relationships
among the classes of a program.
SELF-REVIEW QUESTIONS (see answers in Appendix N)
SR 4.5
What is the difference between an object and a class?
SR 4.6
Describe the instance data of the Die class.
SR 4.7
Which of the methods defined for the Die class can change the state
of a Die object—that is, which of the methods assign values to the
instance data?
 
 
Search WWH ::




Custom Search