Node:Inheritance, Next:, Up:Obj Hierarchies


Immediate super-objects are declared by defining the method super/2 within the object. (Any definition super(Super) is transformed to super(Super,[])). The objects declared by super/2 are the immediate objects from which a method is inherited if not defined within the object. This implies that the inheritance mechanism is an overriding one. One could possibly have a union inheritance, whereby all clauses defining a method are collected from the super hierarchy and executed in a Prolog fashion. This can easily be programmed in SICStus Objects, using delegation to super objects.

The following example shows some objects used for animal classification.

animal :: {}.

bird :: {
        super(animal) &
        skin(feather) &
        habitat(tree) &

penguin :: {
        super(bird) &
        habitat(land) &
        motions(walk) &
        motions(swim) &

| ?- penguin :: motions(M).
M = walk ;
M = swim ;

| ?- penguin :: skin(S).
S = feather ;

The following is an example of multiple inheritance: an object john is both a sportsman and a professor:

john :: {
        super(sportsman) &
        super(professor) &

Inheritance will give priority to the super-objects by the order defined in the super/2 method. Therefore in the above example John's characteristics of being a sportsman will dominate those of being professor. Other kinds of hierarchy traversal can be programmed explicitly using the delegation mechanism.