Java Reference
In-Depth Information
Chain of Responsibility (Chapter 12)
SOLUTION 12.1
Two possible answers follow.
•
Method lookup searches across a well-defined series of
classes.
The C
HAIN
OF
R
ESPONSIBILITY
pattern directs the search for a responsible method to occur across
a series of
objects.
•
The mechanics of method lookup are part of the Java language specification, whereas
C
HAIN
OF
R
ESPONSIBILITY
is under your control as a developer.
SOLUTION 12.2
Your diagram should looking similar to Figure B.16. With this design, any client of
any simulated item can simply ask the item for the responsible engineer. As the next
challenge shows, the code for the various implementations of
getResponsible()
gets
simpler, too.
Figure B.16. Every
SimlulatedItem
object can respond to a
getResponsible()
call.
Internally, a
Simulated-Item
object may forward the request to its parent.