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

Marcus Denker marcus.denker at inria.fr
Tue Feb 5 04:51:00 EST 2019


> 
> Thanks for answer! I want to detect instvar writes only for objects (instances), that was previously fetched from external "datastore" (DB like), so I can persist changed objects only back to the datastore at the end of transaction. These objects can be any existing class (Pharo classes, some 3rd party libs classes, everything), so 1) injecting a class is overkill (affects all objects in the image) 2) impossible to rewrite #class method for every existing class.
> 
> Injecting object-centric metalinks via anonymous subclass breaks up many things, when I want to treat injected object like any othres (IMHO).
> 
> If you will be able to avoid this issue, that would be extra cool :-]
> 
> Note: for now, best for my "instvar writes detection" would be probably hack Object>>#attemptToAssign:withIndex: or ProtoObject>>#modificationForbiddenFor:index:value: and make my "datastore fetched objects" read only (via Object>>#setIsReadOnlyObject:).
> 

The read-only approach has the nice property that it works for collections, too. The meta-link model falls short there (you can not “put a link on offset 4 in this array”, but would need to put it on at:put:)

I started to play with it to see what is needed to create a generalised change detector with read only:
	https://github.com/MarcusDenker/ChangeDetector

	Marcus




More information about the Pharo-users mailing list