Java Reference
In-Depth Information
the head. Placing material on the tail of a conveyor enqueues the material on the conveyor;
removing material from the head dequeues the material from the conveyor. Figure 6.7 shows
the Queue class. The add() method adds an object to the tail of a list, and a call to
remove(0) removes the head of a list.
Figure 6.7. The Queue class defines operations that rely on an abstract List object.
CHALLENGE 6.4
Write the code for dequeue() and enqueue() .
Summary
A common example of B RIDGE occurs in drivers. An application that uses a driver is
an abstraction—the choice of driver determines what happens when the application runs.
The interface between applications and drivers lets you vary either side independently. You
can create new applications that use the drivers without changing the drivers. You can also
add new drivers without changing existing applications. That is the intent of B RIDGE .
You may encounter abstractions that are not decoupled from their implementation but rather
are arranged as an abstract class whose concrete subclasses provide various implementations.
In such a case, you can apply B RIDGE if you want to factor the hierarchy along another line.
Moving the implementations out lets each implementation become a new class that
implements a standard interface. This lets you add new subclasses to the abstraction,
regardless of which implementation of the interface you will use. This move also lets you add
new implementations of the interface without affecting the abstraction hierarchy. The B RIDGE
pattern decouples an abstraction from its implementation so that the two can vary
independently.
Search WWH ::




Custom Search