--- Begin Message ---> On 3 Jan 2019, at 03:17, Esteban Maringolo <emaring...@gmail.com> wrote: > > Hi Paul, > > You can set the object to be "read only" (aka "immutable") and handle the > exception. > > E.g. > > | u | > u := User named: 'Paul'. > u beReadOnlyObject. > [ "your code modifying u's state" ] > on: ModificationForbidden > do: [ :ex | > ex halt. > "inspect state" > u beWritableObject. > ex resume > ]. > > Probably there is a better way to do this with slots, using default ones or > subclassing `InstanceVariableSlot` for that instance only and halting on the > `write:to:` method of it. >I started an experiment to turn the read Only mechanism into a general object change notifier: https://github.com/MarcusDenker/ChangeDetector This allows the following style of use: testObserveObjectWithModification [ | observed observer | observed := 'test2'. observer := self. observed notifyOnChange: observer. "the observed object is now read only" self assert: (observed isReadOnlyObject). "but we can change it!" observed at: 1 put: $T. self assert: observed equals: 'Test2'. "and the method #objectChangeNotified was called, setting flag" self assert: flag equals: #yes. observed stopNotifyOnChange: observer. self deny: (observed isReadOnlyObject). missing: -> we need to model read only for all tracked object (we need to remember the old state and restore it) -> think about threads… is there a problem? Marcus
--- End Message ---
Re: [Pharo-users] Is it possible to follow an object through a computation?
Marcus Denker via Pharo-users Wed, 09 Jan 2019 06:01:01 -0800
- [Pharo-users] Is it possible to follow an ... PAUL DEBRUICKER via Pharo-users
- Re: [Pharo-users] Is it possible to f... Esteban Maringolo
- Re: [Pharo-users] Is it possible ... Marcus Denker via Pharo-users
- Re: [Pharo-users] Is it possible to f... Steven Costiou via Pharo-users