An example code concerning inheritance of object messages:

Rebol[
    Purpose: "Demonstrate non-copied object messages."
    ]

;Define the object without messages
a: make object! [
    num: 1
    ;Other non-message attributes here...
    messages: none
    ]

;Now define the messages, common for all descendants.
;These are created only once
;and aren't copied as long as
;you don't change anything for a descendant...
a/messages: make object! [
    ;An example message
    get-num: func [
        ;every message must have access to object to which it has been
sent...
        obj [object!]
        ;the room for message parameters...
        param
        ] [
        ;This is the body of the message
        obj/num
        ]
    ;Other messages here...
    ]

;Function to send messages, shouldn't be changed
sm: func [obj [object!]  'message [word!] param [block!]] [
    do in obj/messages message obj param
    ]

;Now you can use the code like this:
>> sm a get-num []
== 1
>> b: make a [num: num + 1]
>> sm b get-num []
== 2


- Ladislav

Reply via email to