[Pharo-users] How to intercept instvar write - MetaLinks + anonymous subclass problem

Steven Costiou steven.costiou at kloum.io
Sat Feb 2 05:36:13 EST 2019

> is possible to intercept (before writeú all instance variable writes on every existing objects? 
> Ok, I learned more about MetaLinks and it's perfectly possible to intercept instance variable writes via. installing MetaLink into object instance (cool) - then I can intercept instvar write, but one problem immediately occurs:
> when installing MetaLink into object instance, an original object class is exchanged to anonymous subclass of the original class - and because typical #= method is implemented like:
> =
> self == anObject
> ifTrue: [ ^ true ].
> self class = anObject class
> ifFalse: [ ^ false ].
> ...
> then most of #= comparisons in application logic is broken due to "self class = anObject class" part.
> Is there any way to solve this problem?


the anonymous class thing only happen when you install an object-centric
metalink, i.e. on only one specific object. I also wanted to hide the
anonymous class, or maybe to only make it visible for environment tools.
I need to talk about that with Marcus. 

Why not installing your metalink on the classes of your objects, so that
all instances are affected but in that case there is no anonymous class

If that is not possible, in your case maybe a (temporary) hack would be,
in your case, to add a test in the #class method in Object (or wherever
it is defined): 



    myClass := self class. 

    ^myClass isAnonymous ifTrue:[myClass superclass] ifFalse:[myClass] 

But i did not test that and i have no idea of the overall impact. 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-users_lists.pharo.org/attachments/20190202/f1e68f12/attachment.html>

More information about the Pharo-users mailing list