SE450: Review: OO Mechanisms: Dynamic Dispatch [13/25] Previous pageContentsNext page

Objects may be seen at more abstract (or more concrete) types.

The way an object responds to a message depends upon its actual type.

This is called single dispatch.

GoF: In single-dispatch languages, two criteria determine which operation will fulfill a request: the name of the request and the [actual] type of receiver.

interface I { public void m(); }
class C implements I { public void m() { System.out.println("C.m"); }
class D implements I { public void m() { System.out.println("D.m");
                       public void f() { System.out.println("D.f"); }
class Main {
  public static void main(String[] args) {
    I x = new D();
    x.m();  // prints "D.m"
  }
}

Previous pageContentsNext page