Java Reference
In-Depth Information
Figure 3.1. When a developer of client code thoughtfully defines the client's needs, your
mission is to adapt the interface to an existing class.
Suppose that you are working with a rocket simulation program at Oozinoz, and you want to
include an aerial shell as a "rocket." An aerial shell is a firework that is fired from a mortar ,
or tube, and explodes midflight, ejecting and igniting a collection of stars. A star is
a compressed pellet of a brightly burning, explosive chemical compound. The main difference
between shells and rockets is that shells have a lifting charge and no subsequent thrust,
whereas rockets have a thrust that is fairly continuous through midflight.
The developer of the rocket simulation has thoughtfully provided an interface that defines
the behavior the simulation requires from a rocket:
public interface RocketSim
{
abstract Length apogee();
public Force thrust();
}
This interface is now public, unlike the version in Chapter 2, Introducing Interfaces.
The sidebar Units of Measure on page 24 describes how Oozinoz models physical quantities,
such as length and force.
A key attribute of a shell is its muzzle velocity —the speed at which the shell leaves the
mortar it fires from. Given the muzzle velocity, you can calculate the apogee of the shell. (To
learn about the chemistry and physics of fireworks, I recommend reading The Chemistry of
Fireworks (Russell 2000).) The muzzle velocity also lets you calculate the lifting charge
force, so you can model thrust as an initial spike that quickly drops to zero.
Search WWH ::




Custom Search