Java Reference
In-Depth Information
FIGURE 1.3
The basic
Robot
hierarchy.
Object
1
Robot
Walking Robot
Driving Robot
Now, the hierarchy can become even more specific. With
WalkingRobot
, you might have
several classes:
ScienceRobot
,
GuardRobot
,
SearchRobot
, and so on. As an alternative,
you could factor out still more functionality and have intermediate classes for
TwoLegged
and
FourLegged
robots, with different behaviors for each (see Figure 1.4).
FIGURE 1.4
Two-legged and
four-legged walking
robots.
Walking Robot
Two-Legged
Walking Robot
Four-Legged
Walking Robot
Guard Robot
Science Robot
Search Robot
Finally, the hierarchy is done, and you have a place for
VolcanoRobot
. It can be a sub-
class of
ScienceRobot
, which is a subclass of
WalkingRobot
, which is a subclass of
Robot
, which is a subclass of
Object
.