Next: obj-exp-instance_method, Previous: obj-exp-fetch_slot, Up: obj-exp [Contents][Index]
inherit/1
declaration:- inherit +ClassName +Op +Name/+Arity, ….
atom
message_operator
atom
integer
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.
Be careful of the precedences of the message
operator and the /
operator. You may need to use parentheses.
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.
uninherit/1