findPhone
¥abstract class DeptDirectory {
¥    abstract String findPhone(String key);
¥}
¥
¥class Empty extends DeptDirectory {
¥  String findPhone(String key) {
¥    return null;
¥  }
¥  public String toString() { return "Empty()"; }
¥}
¥
¥class NonEmpty extends DeptDirectory {
¥  Entry first;
¥  DeptDirectory rest;
¥  NonEmpty(Entry f, DeptDirectory r) {
¥    this.first = f;
¥    this.rest = r;
¥  }
¥  Entry getFirst() { return this.first; }
¥  DeptDirectory getRest() { return this.rest; }
¥  String findPhone(String key) {
¥    if (key.equals(first.getName()))
¥      return first.getPhone();
¥    else return rest.findPhone(key);
¥  }
¥  public String toString() { return "NonEmpty(" + first + ", " + rest + ")";  }
¥}
¥