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

[REBOL] Re: Object private member (was: objects: overhead, private data, naming

From: coussement:c:js:mil:be at: 21-Sep-2001 11:05

Romano & Joel: Thanks guys ! This thread is becoming _very_ interesting ;-) It does me recall one about embedded objects a few months ago. Let's go back to the subject of the first post (from Gregg Irwin I think) ... If I have understand all it has been written - which I seriously doubt ;) - it should be possible to implement privacy in a way, using the property "use [b][context [set 'b 4 a: 3]]" where "b is local at Use block because 'b is NOT defined in the object" : <code> ;--- (using Gregg's naming convention:) use [_print-a _print-b _b][ ctx: context [ ;--> declare public members a: 5 get-a: does [_print-a] get-b: does [_print-b] ;--> declare private members set '_b 20 set '_print-a does [print a] set '_print-b does [print _b] ] ] </code> So, the private members should be only _visible_ from inside the context of the object... Let's test it:
>>; are the public members visible from the global
[ context, through the object definition ?
>> ctx/a
== 5
>>; are the public members visible from the global
[ context, and are the private members visible from [ inside the object ?
>> ctx/get-a
5
>> ctx/get-b
20
>>; YES => OK >>; are any members directly visible from the
[ global context ?
>> a
** Script Error: a has no value ** Near: a
>> _b
** Script Error: _b has no value ** Near: _b
>> _print-a
** Script Error: _print-a has no value ** Near: _print-a
>> _print-b
** Script Error: _print-b has no value ** Near: _print-b
>>; NO => OK >>; are the private members visible from the
[ global context, through the object definition ?
>> ctx/_b
** Script Error: Invalid path value: _b ** Near: ctx/_b
>> ctx/_print-a
** Script Error: Invalid path value: _print-a ** Near: ctx/_print-a
>> ctx/_print-b
** Script Error: Invalid path value: _print-b ** Near: ctx/_print-b
>>; NO => OK
Isn't it the effect we were trying to reach, or did I miss something ? ==christophe