Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] objects without overhead Re:

From: jelinem1:nationwide at: 18-Oct-2000 9:12

To create only one instance of the function, define the function first and assign it to a word. Then, assign the object element to a reference of this word. Example: my-func: func [][print "hello!"] obj1: make object! [f: :my-func] obj2: make object! [f: :my-func] same? (get in obj1 'f) (get in obj2 'f) == true - Michael Jelinek [rishi--picostar--com] on 10/17/2000 04:44:00 PM From: [rishi--picostar--com] on 10/17/2000 04:44 PM Please respond to [list--rebol--com] To: [list--rebol--com] cc: Subject: [REBOL] objects without overhead 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.