Java Reference
In-Depth Information
Figure 6.4. Instances of classes in the
MachineController
hierarchy drive machines in
the Oozinoz factory.
The
MachineController
class defines the interface for an object that controls a machine.
Subclasses provide different implementations of the methods that drive a machine. Most of
the methods that
Machine-Controller
declares are abstract, but it does have concrete
methods that depend on its
abstract methods.
For example, the
inputFull()
method is
concrete, but its effects depend on how subclasses implement
getQueueMax()
:
public boolean inputFull()
{
return getQueueMax() >= getQueue().size();
}
The
MachineController
class is an abstraction whose implementation occurs in its
subclasses, and we can consider separating the abstraction from its implementation. The
motivation to separate an abstraction from its implementation usually occurs when a new
reason for subclassing emerges. For example, suppose that you want to differentiate normal
controllers from testing controllers. A testing controller has new methods that test or stress
machines, such as an
overflow()
method that dispatches material to a machine until the