Try OpenEdge Now
skip to main content
Object-oriented Programming
Designing Objects: Inheritance, Polymorphism, and Delegation : Interface hierarchies and inheritance : Duplicate members in a hierarchy
 

Duplicate members in a hierarchy

Without interface inheritance, a class can implement more than one interface with multiple interfaces that include identical member signatures. In this case, the class is required to implement only one member that satisfies the identical signature in multiple interfaces.
With interface inheritance, the same rules apply. Multiple identical members appearing in different interfaces within the hierarchy are allowed and require only one implementation in the implementing class. Member types in the hierarchy that differ only by return type will generate compile time errors. Overloaded members may appear within the same interface, or in different interfaces within the hierarchy. This is comparable to existing rules with respect to overloading.
INTERFACE IMyTop:
  DEFINE PUBLIC PROPERTY myInteger AS INTEGER
    GET.
    SET.
END INTERFACE.
INTERFACE IMyBottom INHERITS IMyTop:
  DEFINE PUBLIC PROPERTY myInteger AS INTEGER
    GET.
    SET.
END INTERFACE.
CLASS MyImplementation IMPLEMENTS IMyBottom :
  DEFINE PUBLIC PROPERTY myInteger AS INTEGER
    GET():
      RETURN myInteger.
    END GET.
    SET(INPUT val AS INTEGER):
      myInteger = val.
    END SET.
END CLASS.
In the above example, it is allowed for interface IMyBottom to have its own definition of the existing property, myInteger that appears in IMyTop interface. Also, the class MyImplementation needs to implement only the single property that satisfies them both.