[Newbies] 'locking' an object

Randal L. Schwartz merlyn at stonehenge.com
Thu Oct 2 17:26:36 UTC 2008


>>>>> "Marcin" == Marcin Tustin <mm3 at zepler.net> writes:

Marcin> Surely if you have a wrapper class which only holds a reference to a
Marcin> single object that has all of the data, and that has accessors, then
Marcin> the wrapper can only use the accessors? The data object could have a
Marcin> flag that causes all of the accessors to throw an exception when it is
Marcin> set.

Well, if everyone using the object promises to play nice, sure.

But the debugger doesn't have any special privileges, and it can clearly
access every inst var, regardless of whether accessors exist or not, through
the magic of #instVarAt: and friends.

So code would merely have to execute the equivalent of the primitives behind
#instVarAt: and #instVarAt:put:, and no amount of wrapper class would help.

If the problem is "how do I ensure this object *doesn't* get mutated?", this
is not a complete solution, just a slow simulation as long as everyone
cooperates.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


More information about the Beginners mailing list