previous
|
start
|
next
Using Interfaces for Callbacks
Limitations of
Measurable
interface:
Can add
Measurable
interface only to classes under your control
Can measure an object in only one way
E.g., cannot analyze a set of savings accounts both by bank balance and by interest rate
Callback mechanism: allows a class to call back a specific method when it needs more information
In previous
DataSet
implementation, responsibility of measuring lies with the added objects themselves
Alternative: Hand the object to be measured to a method:
public interface Measurer { double measure(Object anObject); }
Object
is the "lowest common denominator" of all classes
previous
|
start
|
next