Java Reference
In-Depth Information
forwarding to implement the interface. And if the general implement-
ation provided is incorrect, they can write their own implementation.
You can even provide multiple possible implementations of the interface
to prospective users. Whatever implementation strategy programmers
prefer, the objects they create are
Attributed
.
Exercise 4.1
: Rewrite your solution to Exercise 3.6 on page
99
using
an interface for
EnergySource
instead of an abstract class.
Exercise 4.2
: Rewrite your solution to Exercise 3.12 on page
114
using
an interface if you didn't write it that way in the first place.
Exercise 4.3
: Should the
LinkedList
class from previous exercises be an
interface? Rewrite it that way with an implementation class before you
decide.
Exercise 4.4
: Design a collection class hierarchy using only interfaces.
Exercise 4.5
: Think about whether the following types should be
represented as interfaces, abstract classes, or concrete classes: (a)
treeNode
to represent nodes in an N-ary tree; (b)
treeWalker
to walk the
tree in a particular order (such as depth-first or breadth-first); (c)
Draw-
able
for objects that can be drawn by a graphics system; (d)
Application
for programs that can be run from a graphical desktop.
Exercise 4.6
: What changes in your assumptions about each of the
problems in Exercise 4.5 would make you change your answers?
There are two ways of constructing a software design: one way is
to make it so simple that there are obviously no deficiencies; the
other is to make it so complicated that there are no obvious defi-
ciencies.
C.A.R. Hoare