CS 310, Object-Oriented Programming with Java

Quiz 11, 10 April 2008


  1. Explain why the relation between Adapter classes and event Listeners makes Adapters an improvement over Listeners.


    An Adapter class implements a Listener interface, overriding each method in the interface with an empty method. Code that needs only a few of the methods in a Listener interface can extend the associated Adapter class, overriding the methods it wants to use and ignoring the rest. If the code had used the Listener interface, it would have to define all the methods, whether it used them or not (Adapter Classes, page 300 (7th ed.) or 338 (8th ed.)).

  2. Explain how Java's delegation model introduces flexibility in the way programs handle events.


    Java's delegation model decouples the event source from the event responder, allowing any class instance of suitable parentage to serve (to be delegated) as the responder. Page 286 (7th ed.) or 324 (8th ed.).


This page last modified on 31 March 2008.