Java Reference
In-Depth Information
CHALLENGE 21.2
Write
the
code
for
the markMoldIncomplete()
method
of
OzAsterStarPress .
package com.oozinoz.aster.client;
import com.oozinoz.aster.*;
public class OzAsterStarPress extends AsterStarPress
{
public MaterialManager getManager()
{
return MaterialManager.getManager();
}
public void markMoldIncomplete(int id)
{
/* ? */
}
}
The Aster star press developers are well aware of how fireworks factories work and have done
a good job of communicating with the factory at the right processing points. Nonetheless, you
may need to establish communication at a point that the Aster developers have not foreseen.
Template Method Hooks
A hook is a method call that a developer places in his or her code to give other developers a
chance to insert code at a specific spot in a procedure. When you are adapting another
developer's code and you need control at a point where you don't currently have it, you can
request a hook. An obliging developer can add a method call at the point that you need it.
The developer will also usually supply a stubbed-out version of the hook method so that other
clients need not necessarily override the hook method.
Consider the Aster star press that discharges its chemical paste and flushes itself with water
when shutting down. The press has to discharge this paste to keep it from drying and clogging
the machine. At Oozinoz, you recover this paste so that you can dice it for use as tiny stars in
Roman candles. (A Roman candle is a stationary tube that contains a mixture of explosive
charges, sparks, and stars.) After the star press discharges the paste, you arrange for a robot to
move the paste to a separate conveyor, as Figure 21.2 shows. It is critical that you remove
the paste before the machine flushes its processing area with water, which would ruin the
paste mixture.
The problem is that you want to gain control between the two statements:
dischargePaste();
flush();
You might override dischargePaste() with a method that adds a call to collect the paste:
Search WWH ::




Custom Search