Java Reference
In-Depth Information
CHAPTER
3
Object interaction
Main concepts discussed in this chapter:
abstraction
modularization
object creation
object diagrams
method calls
debuggers
Java constructs discussed in this chapter:
class types, logic operators (&&, ││ ), string concatenation, modulo operator ( % ), object
construction ( new ), method calls (dot notation), this
In the previous chapters, we have examined what objects are and how they are implemented. In
particular, we discussed fields, constructors, and methods when we looked at class definitions.
We shall now go one step further. To construct interesting applications, it is not enough to build
individual working objects. Instead, objects must be combined so that they cooperate to per-
form a common task. In this chapter, we shall build a small application from three objects and
arrange for methods to call other methods to achieve their goal.
3.1
The clock example
The project we shall use to discuss interaction of objects is a display for a digital clock. The
display shows hours and minutes, separated by a colon (Figure 3.1). For this exercise, we
shall first build a clock with a European-style 24-hour display. Thus, the display shows the
time from 00:00 (midnight) to 23:59 (one minute before midnight). It turns out on closer in-
spection that building a 12-hour clock is slightly more difficult than it is for a 24-hour clock;
we shall leave this to the end of this chapter.
Figure 3.1
A display of a digital
clock
11:03
 
 
 
Search WWH ::




Custom Search