interfacesandpolymorphism.pptVIP

  • 11
  • 0
  • 约1.28万字
  • 约 41页
  • 2016-10-06 发布于天津
  • 举报
interfacesandpolymorphism

Using Interfaces for Callbacks add method asks measurer (and not the added object) to do the measuring public void add(Object x) { sum = sum + measurer.measure(x); if (count == 0 || measurer.measure(maximum) measurer.measure(x)) maximum = x; count++; } Using Interfaces for Callbacks You can define measurers to take on any kind of measurement public class RectangleMeasurer implements Measurer { public double measure(Object anObject) { Rectangle aRectangle = (Rectangle) anObject; double area = aRectangle.getWidth() * aRectangle.getHeight();

文档评论(0)

1亿VIP精品文档

相关文档