Well...I thought about this a bit and I THINK I found an elegant solution. So I guess
I'll respond to my own question...
I think the solution to this problem is inner objects. Here is an example:
myobject: make object! [
- function1: func[][..]
- function2: func[][..]
- .
- .
- make: func[var1 var2 var3][
- return make object! [
- instancevar1: var1
- instancevar2: var2
- instancevar3: var3
-
- instancefunc1: function1 ;copies a reference to function1 above...
- instancefunc2: function2
- ]
- ]
]
;;;create instance of object
coolobj: myobject/make
coolobj/instancfunc1 ; all instances access same function! less overhead if many
objects!!!
.
.
.
I am not sure if this would work since I have never tested it (yet). The questions in
my mind are:
1. are functions copied by reference or value? if by value, this would not solve my
problem
2. do inner objects have access to outer object words? for example, can 'instancefunc1
access 'function1 as shown above?
I hope this works. If it does, it would be a very simple but elegant solution to my
problem. It would be even more elegent when modules come around so I can keep all
private words in context of myobject rather than the actual object returned...making
code very clear.
Rishi
Previously, you ([EMAIL PROTECTED]) wrote:
> I am working on a program which requires about 1000 or so instances of objects. It
>doesn't have to be OO but I like the design better that way. I am using a function as
>constructor like the following example (not real code..):
>
> ;I used dashes to keep formatting intact (hopefully this works)
>
> make_myobject: func[var1 var2 var3][
> --return make object! [
> ----instancevar1: var1
> ----instancevar2: var2
> ----instancevar3: var3
>
> ----instancefunc1: func[][...]
> ----------------.
> ----------------.
> ----------------.
> -]
> ]
>
>
> The thing I don't like about this solution is that every instance of this object has
>duplicate copies of the functions (As far as I know...please correct me if I am
>wrong). This seems like a waste to me - especially if the object has 50 or so
>functions. Is there any OO way in Rebol to create multiple instances of this object
>without creating multiple copies of the functions associated with each object? I know
>how to do this in a non-object oriented fashion but would like to see an OO solution.
>
>