Design Patterns Java™ Workbook

(Michael S) #1
Chapter 14. Introducing Construction

Figure 14.2. The Firework class "inherits" classification constants by implementing
the ClassificationConstants interface.

CHALLENGE 14.3


Suppose that you want to use constructors to establish the default classification of
afirework as DISPLAY. Write constructors for Firework that ensure this, and
make them collaborate so that the one-parameter constructor uses the two-parameter
constructor.

Changing the constructors for the Firework class forces us to consider changing
the constructors for its subclass, Fountain.


CHALLENGE 14.4


Suppose that you want the Fountainclass to abide by the decision that the default
classification of a firework is DISPLAY. It is better not have this decision appear
twice in the code. Write the constructors for Fountainso that they collaborate
effectively with the superclass constructors, including observance of the superclass's
ideas about defaults.
Free download pdf