Comment #3 on issue 3648 by marianopeck: A "Stratified" proxy in smalltalk
http://code.google.com/p/pharo/issues/detail?id=3648

Hi Igor. I remember you showed me this implementation once I was asking about how to do proxies for classes. It works, but there is something I don't like: having to do the shallow copy of the class.

createHandler
" This method will create a handler - an anonymous class, which will receive the
        #handleMessage:forProxy: message.
To get a proxy object, you must instantiate a handler instance by sending #basicNew to it.
        See my subclasses for examples "
        ^ self shallowCopy
                methodDict: nil;
                superclass: self


I don't like that because for EACH proxy, I have to instantiate a new class (an object with a lot of intsVars) and an instance of that class.

In my case, I want to create a lot of proxies and the memory is important, so that solution doesn't scale. What we did is to use the same proxy as the metaclass. So we defined for example:

ProtoObject subclass: #ClassProxy
        instanceVariableNames: 'superclass methodDict format fileName'
        classVariableNames: ''
        poolDictionaries: ''
        category: 'Proxies'


ClassProxy >> initialize
        super initialize.
        superclass := ProxySuperclass.
        methodDict := nil.
        fileName := nil.

ProxySuperclass >> cannotInterpret: aMessage
^ ClassProxyHandler mareaHandleCannotInterpret: aMessage for: aMessage lookupClass receiver: self
        
        
Anyway, if you are interested, take a look to the package Proxies in http://www.squeaksource.com/Marea



Reply via email to