Professional Documents
Culture Documents
The components of a class have visibility sections, which define the external point
of contact between the class and its consumer. For example, the public components
of a class define its public scope, since all of its attributes and method
parameters can be addressed by all consumers. The protected components are an
interface between the class and those classes that inherit from it (the
subclasses).
Interfaces are independent structures that enable the class-specific public points
of contact to be enhanced by implementing them in classes. Different classes that
implement the same interface can all be addressed in the same way. Alongside
inheritance, interfaces are one of the pillars of polymorphism, since they allow a
single method within an interface to behave differently in different classes.
Interface reference variables allow consumers to address different classes in the
same manner. Interfaces can also be nested.
Defining Interfaces
Interface Components
Implementing Interfaces
Interface Reference Variables
Accessing Objects Using Interface References
Accessing the Static Components of Interfaces
Defining Interfaces
Interface Components
Implementing Interfaces
The class must implement the methods of all interfaces implemented in it. The
implementation part of the class must contain a method implementation for each non-
abstract and non-optional interface method meth:
METHOD intf~meth.
...
ENDMETHOD.
Interface methods defined as optional using the addition DEFAULT do not need to be
implemented explicitly and demonstrate default behavior when called.
To create an object of the class class, a reference variable cref must first be
declared with reference to the class. If the class class implements an interface
intf, the class reference variable cref can be assigned to the interface reference
variable iref as follows:
iref = cref.
The reference in iref now points to the same object as the reference in cref.
As far as the static components of interfaces are concerned, the interface name can
only be used to access constants.
Accessing a constant const: intf=>const
For all other static components of an interface, only object references or the
class class that implements the interface can be used.
Accessing a static attribute attr:class=>intf~attr
Calling a static method meth: class=>intf~meth( )