Try OpenEdge Now
skip to main content
Object-oriented Programming
Getting Started with Classes, Interfaces, and Objects : Defining interfaces

Defining interfaces

An interface declares prototypes for a set of instance properties, methods, and events that a class must define if the class definition implements the specified interface. An interface also represents a user-defined object type that defines only property, method, and event names and signatures, along with any temp-table and ProDataSet definitions used as parameters to those properties, methods, and events.
A class can implement zero or more interfaces. Thus, interfaces provide a way for a class to satisfy the requirements of more than one set of behaviors while only being able to inherit a single set of behaviors from its super class. If some behaviors represent a set of properties, methods, or events that other objects need to invoke or access, but for which there is no common implementation, an interface provides a reliable way of defining a uniform contract that all implementations of its properties, methods, and events must satisfy. Any caller can then count on the consistent definition of a set of properties, methods, and events and their signatures, even though the implementation of these same properties, methods, and events might differ completely from one class to another.
Note that an abstract class provides a similar mechanism for defining a contract that an implementing class must satisfy. However, an abstract class enforces its contract through inheritance by a subclass. Unlike an interface, an abstract class can define implemented members that it also provides to the inheriting class hierarchy. This allows an abstract class to enforce a common implementation among class hierarchies in which it participates, in addition to any abstract members that it defines. The class that inherits from an abstract class can also implement an interface that declares prototypes for both the abstract and implemented class members that it inherits.