Class Extension
Extension represents the "is-a" relationship. When a class extends another class, it's called a subclass of that class. Conversely, the class being extended is called a superclass of that subclass.
A subclass inherits all of the public methods and properties (collectively called members) of the class it extends. These members can be overridden by declarations of methods and properties in the subclass.
Note:
Application classes have no multiple inheritance (that is, being able to extend more than one class.)
Type checking in PeopleCode (both at design time and runtime) does strong type checking of application classes, tracking each application class as a separate type. A subclass can be used as the class it extends, because it implements the public interfaces of its superclass. This is called subtyping.
In the following example, the class Banana extends the class Fruit. Banana is the subclass of Fruit. From Fruit, you can extend to Bananas. However, from Bananas you can't extend to Fruit. Another way to think about this is you can only extend from the general to the specific, not the other way around.
class Fruit
method DoFruit();
property number FruitNum instance;
end-class;
class Banana extends Fruit
method DoBanana();
property number BananaNum instance;
end-class;The following code shows a correct way to assign a class object, because Banana is a subtype of Fruit.
local Fruit &Bref = create Banana(); The following is not correct. Banana is a subtype of Fruit. Fruit is not a subtype of Banana. This assignment causes an error at design time.
local Banana &Fref = create Fruit(); Before you can extend a class, you must first import it. You must import all class names you use in a PeopleCode program before you use them.
Related Topics