Next: , Previous: , Up: obj-exp   [Contents][Index]


10.30.6.18 inherit/1  declaration

Synopsis

:- inherit +ClassName +Op +Name/+Arity, .

Arguments

ClassName

atom

Op

message_operator

Name

atom

Arity

integer

Description

ClassName names the class from which the message should be inherited, Op indicates which kind of message it is, and Name and Arity indicate the name and arity of the message to be inherited. You may include several inheritance specifications in one directive.

Caveat

Be careful of the precedences of the message operator and the / operator. You may need to use parentheses.

Examples

Suppose classes toy and truck are defined as follows:

:-class toy. 
Self <- create. 
Self >> size(small).
Self >> rolls(false). 
:- end_class toy.

:- class truck. 
Self <- create. 
Self >> size(small).
Self >> rolls(true). 
:- end_class truck.

Then toy_truck inherits its size from toy and the fact that it rolls from truck:

:- class toy_truck = toy + truck. 
:- inherit      
        toy <- (create/O), 
        toy <- (size/1), 
        truck <- (rolls/1).
:- end_class toy_truck.

Note that this is just a toy example.

See Also

uninherit/1


Send feedback on this subject.