Java Reference
In-Depth Information
To achieve this, we use one string field and a method:
public class ClockDisplay
{
private String displayString;
Other fields and methods omitted.
/**
* Update the internal string that represents the display.
*/
private void updateDisplay()
{
Method implementation omitted.
}
}
Whenever we want the display of the clock to change, we shall call the internal method up-
dateDisplay . In our simulation, this method will change the display string (we will examine
the source code to do this below). In a real clock, this method would also exist; there it would
change the real clock display.
Apart from the display string, the ClockDisplay class has only two more fields: hours and
minutes . Each of these fields can hold an object of type NumberDisplay . The logical value
of the clock's display (the current time) is stored in these NumberDisplay objects. Figure 3.4
shows an object diagram of this application when the current time is 15:23.
Figure 3.4
Object diagram
of the clock display
P\'LVSOD\
&ORFN'LVSOD\
1XPEHU'LVSOD\
KRXUV
OLPLW
PLQXWHV
YDOXH
1XPEHU'LVSOD\
OLPLW
YDOXH
 
Search WWH ::




Custom Search