Using Interfaces for Callbacks

 public interface Measurer
 {
    double measure(Object anObject);
 }

Measurer m = new RectangleMeasurer();
DataSet data = new DataSet(m);
data.add(new Rectangle(5, 10, 20, 30));
data.add(new Rectangle(10, 20, 30, 40)); . . .

Click here for Example of Measurer Interface.

Suppose you want to use the DataSet class of Section 9.1 to find the longest String from a set of inputs. Why can't this work?

   Answer: The String class doesn't implement the Measurable interface.


Why does the measure method of the Measurer interface have one more parameter than the getMeasure method of the Measurable interface?

   Answer: A measurer measures an object, whereas getMeasure measures "itself", that is, the implicit parameter.