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

[REBOL] Re: Private Object Function

From: rebol:techscribe at: 16-Jan-2001 14:26

Hi Christophe, 1. I think the DBMS I developed in my REBOL book (REBOL The Official Guide) may be a starting point (chapters 15-18). It's not the "last word" in developing a dbms under REBOL, but it does provide some thoughts and examples that may be useful for you. I think the Object Navigator might come in handy. 2.
> [In the specific context of my try for OODBMS development, the > persistence of the DBobject should indeed request to be written down > INCLUDING the private methods, because those should contain some business > intelligence needed to access/handle the contained data]
You want strictly enforced privacy, and you want the ability to save objects including their private componenets. From the point of view of privacy enforcement REBOL's built-in storage functions (write, save) are non-members that are prohibited from accessing the private components. If they are prevented from accessing the private components, how should they be able to save these private components, unless they are used from within member functions? The OODBMSs I am aware of use two strategies to save objects: a) Each object includes serialization functions used to store the object. Since the serialization functions are members of the object, they do have access to private object conponents. This can be implemented in REBOL. b) The OODBMS uses runtime system information (RTTI) to invade the privacy of the object and automatically determine the components and component types of an object. This can also be implemented in REBOL.
> [you're right ! methods would be classified in three exclusives > classes: public, private and protected
You appear to follow the Object Pascal (Delphi) conventions.
> Sample use of them could be: > - public access : the method can be called from any script in the > application.
This is supported in REBOL using paths, or GETting a value IN an object (i.e. get in object 'word).
> - private access : the method can be called only from scripts in the > object for which the function was declared (including the sub-objects); the > method cannot be called from descendant of the object.
Hidden objects or contexts are not protected from descendants. 
> - protected access : the method can be called only from scripts for > the object for which the function was declared, and its descendant.
Hidden objects or contexts are exposed to descendants.
> > c) Under no circumstances must a non-member function be able to access > > private components? > [as I see the implementation for now, my meaning of it is to enforce > the protection of the object's contain by keeping the protected/private part > out-of-bound for the context from which the object is called. That is, using > your words, your point c).
See what I wrote above. If you enforce c) then you cannot use REBOL's default functions for saving an object from outside of the object. The serialization functions included IN objects can - of course - make use of write and save. Example:
>> o: make object! [
e: none save-me: func [filename] [write/append filename mold self] make object! [ h: does [print "I'm hidden."] set 'e does [h] append second save-me [write/append mold self] ] ]
>> probe o
make object! [ e: func [] [h] save-me: func [filename][write/append filename mold self write/append filename mold self] ] save-me looks like its saving self twice. These are two different selfs. The first self is bound in the context of the public object, the second self is bound int the object used to hide the h function. I.e. the second self evaluates to the "hidden" object. We can see that by retrieving the body of the save-me function: get second in o 'save-me, and then getting and displaying the two self words, using get second ... and get fourth ... respectively, to get the value associated with the second word (self), and the fourth word (self) in the block:
>> print mold get second second get in o 'save-me
make object! [ e: func [][h] save-me: func [filename][write/append filename mold self write/append filename mold self] ]
>> print mold get fourth second get in o 'save-me
make object! [ h: func [][print "I'm hidden."] ] Note that - as demonstrated - it is possible to get at the hidden stuff, if you go out of your way to do so. The solution IMHO is to implement your own objects and supporting function in which you enforce private/protected/public rules. As long as your code does not use REBOL's built-in functions to violate these rules, you're fine, provided you don't mind the extra overhead. Take Care, Elan