Ciao Volker,
        I did little modifications but your code filly works. A last
question remains:

-------------------------------------------
REBOL [
        TITTLE: "Right method"
        VERSION: 1.1
        AUTHOR: "Volker Nitsch"
        MODIFICATIONS: "by Giuseppe Chillemi a newbie that needs to fully
understand the code ;)"
        ]

methods1: context[
 f1: func[obj][print ["f1 on" obj/type obj/name]] ]


proto1: context[
 name: none
 type: 'proto1
 methods: []
]

; subclass:

methods2: context[
 f1: func[obj][print ["f1 on" obj/type obj/name]] ]


proto2: make proto1 [
 type: 'proto2
 methods: []
]

; instance with different functions referred as external objects

inst1: make proto1 [name: "inst1" methods: methods1]
inst2: make proto2 [name: "inst2" methods: methods2]

proto-f1: func[obj][
 obj/methods/f1 obj
]

proto-f1 inst1
proto-f1 inst2

;now lets change f1 on methods2

methods2/f1: func[obj][print ["Mama told me I am" obj/type obj/name]]

;f1 changed and it reflects on the objects too which uses methods2/f1 .
NICE!

proto-f1 inst1
proto-f1 inst2

-------------------------------------------------

I have been tempted to write

methods2/f1: print ["Mama told me I am" SELF/type SELF/name]

But it didn't work.

Some question remains on this topic

Is there a way change the function of an object which refers to itself =
using
SELF after the creation of an object ?

myproto: [
        fullname: "Giuseppe Chillemi"
        second: "Surprise"
        protofunc: does [print self/fullname]
        ]

myobj: context myproto
myobj/protofunc

newfunc: does [print self/second]

myobj/protofunc: :newfunc
myobj/protofunc

Is there a way to change myproto/protofunc FUNCTIONTEXT before the =
creation
of myobj object (having in this way self defining code)

Thank you in advance and for your time.

Giuseppe


-----Messaggio originale-----
Da: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Per conto di
Volker Nitsch
Inviato: luned=EC 7 novembre 2005 3.19
A: [EMAIL PROTECTED]
Oggetto: [REBOL] Re: Question about REBOL objects and reusabilty of =
code.


On 11/5/05, Giuseppe Chillemi <[EMAIL PROTECTED]> wrote:
> Hello, I am starting my experiments with Rebol. I want to write a =
small
> application to learn more about Rebol objects.
>
>
>
> I need to have an array of the same object. The object contains data =
and
> code (methods). The methods code should be defined at the creation of =
the
> instance of the object. The method "interface" will always be the same =
an=3D
d
> method will have  5/6 different kind of code in N (even >10.000) =
instance=3D
s
> the object.
>
> The question are:
>
> - does Rebol create in memory a new instance of the method code for =
each
> instance of the object ?
>
> - could I reuse the same 5/6 kinds of code without duplicating the =
code i=3D
n
> memory when I generate a new instance of the same object  (In other =
words=3D
 a
> relative link to code) ?
>
>
>
> The main goal is to save memory and have speed.
>

; Its a little awkward, but possible.
; view-faces do it similar to this:

methods1: context[
 f1: func[obj][print ["f1 on" obj/type obj/name]]
]

proto-f1: func[obj][
 obj/methods/f1 obj
]

proto1: context[
 name: none
 type: 'proto1
 methods: methods1
]

; subclass:

methods2: make methods1[
 f1: func[obj][print ["f1 on" obj/type obj/name]]
]

proto2: make proto1 [
 type: 'proto2
 methods: methods2
]

; instance:

inst1: make proto1 [name: "inst1"]
inst2: make proto2 [name: "inst2"]

proto-f1 inst1
proto-f1 inst2

>
>
> Thank you in advance
>
>
>
>             Giuseppe Chillemi
>
>
>
>
>
>
>
> --
> To unsubscribe from the list, just send an email to
> lists at rebol.com with unsubscribe as the subject.
>
>


--
-Volker

"Any problem in computer science can be solved with another layer of
indirection. But that usually will create another problem." David
Wheeler
--=20
To unsubscribe from the list, just send an email to=20
lists at rebol.com with unsubscribe as the subject.

-- 
To unsubscribe from the list, just send an email to 
lists at rebol.com with unsubscribe as the subject.

Reply via email to