[Pharo-project] short circuit or redirecting selectors
Hello, If I have an object with accessors #firstName, #lastName and #age, how would I short shirt circuit or replace these selectors? In other words, how would I modify an object after it's already been created? Thanks, Elliot
On Dec 20, 2010, at 3:46 AM, Elliot Finley wrote:
Hello,
If I have an object with accessors #firstName, #lastName and #age, how would I short shirt circuit or replace these selectors? In other words, how would I modify an object after it's already been created?
Hello there are plenty of ways to do that but I think that this is not what you want to do. Tell us what you are trying to achieve? Did you read smalltalk by example from my web page? There is a chapter on object creation and instantiation. Stef
Thanks, Elliot
On Mon, Dec 20, 2010 at 1:13 AM, Stéphane Ducasse <stephane.ducasse@inria.fr
wrote:
On Dec 20, 2010, at 3:46 AM, Elliot Finley wrote:
Hello,
If I have an object with accessors #firstName, #lastName and #age, how would I short shirt circuit or replace these selectors? In other words, how would I modify an object after it's already been created?
Hello
there are plenty of ways to do that but I think that this is not what you want to do. Tell us what you are trying to achieve?
Did you read smalltalk by example from my web page? There is a chapter on object creation and instantiation.
Stef
I haven't, I'll see if I can find it.
I'm trying to create a memento that will work for a facade. Currently I have: IFBaseModel >> memento | memento | memento := self copy. memento refModel: self. ^ memento. Which works for a normal model object. But a facade wouldn't be storing it's values in instance variables. It would be proxying for one or more underlying model objects and so would a copy of that object. So rather than have the memento just be a simple copy of the object, I want it to be a copy of the object and intercept the relevant accessors (I have a list) and redirect them to a dictionary. Then after validation, etc. the updateRefModel selector on the memento would update the underlying model or facade. Thus it would work for both normal models and facades. Elliot
There is an implementation of memento in magritte if you want to get some inspiration.
Which works for a normal model object. But a facade wouldn't be storing it's values in instance variables. It would be proxying for one or more underlying model objects and so would a copy of that object. So rather than have the memento just be a simple copy of the object,
A memento does not have to be a copy, it can just have the same api and store the info in a dict and once validated update the model.
I want it to be a copy of the object and intercept the relevant accessors (I have a list) and redirect them to a dictionary. Then after validation, etc. the updateRefModel selector on the memento would update the underlying model or facade. Thus it would work for both normal models and facades.
you can compile on the fly new methods and use instVarAt:.... but I would not use meta programming in simple model. Stef
Elliot
participants (2)
-
Elliot Finley -
Stéphane Ducasse