Hi everyone,
I have made a class Company with an instance variable companyName and the accessors. I also created a second class SomeotherModel with an #update method. I use the following code: Company>>companyName ^companyName Company>>companyName: aString companyName := aString. self changed. SomeotherModel>>update self halt. company := Company new. viewObj := SomeotherModel new. coName := ValueAspectAdaptor subject: company to: #companyName. coName when: #valueChanged send #update to: viewObj. coName value: 'Meezon Software'. At this point I get sent an #update in viewObj. Is this the correct way to notify a SomeotherModel object that there was a change in the companyName of Company object? Basically I would like to know what the easiest way is to notify an object when there is a change in another object. I have looked ar Valueholder but that is not as good. Thanks Costas |
Costas,
If I understand what you're trying to do, a value aspect adaptor is not really going to help. The idea behind value aspect adaptors is to allow generic views (and other objects) to use #value/#value: to work with any aspect of another object by inserting an adaptor between the view and the adaptee. It sounds like your goal is to have the model trigger notifications when an aspect's value changes. You can achieve this in at lease a couple of ways. One is to simply #trigger: from the setter method. Another is to store the aspect in a value holder, and provide getter and setter methods to get/set the value of the contained value model. You would still have to do something to allow interested parties to see the changes, either by allowing them to "see" the value model and register interest in its events, or by observing the changes and triggering events from the model. It might also help to look at http://www.object-arts.com/wiki/html/Dolphin/EventMechanism.htm http://www.object-arts.com/wiki/html/Dolphin/MVP.htm Have a good one, Bill -- Wilhelm K. Schwab, Ph.D. [hidden email] |
Costas,
Just to add a bit more to Bill's answer. The simplest way, as Bill says, is to do the triggering yourself Company>>companyName ^companyName Company>>companyName: aString companyName := aString. self trigger: #companyNameChanged SomeotherModel>>update self halt. company := Company new. viewObj := SomeotherModel new. company when: #companyNameChanged send #update to: viewObj. company companyName: 'Meezon Software'. If you have a large number of Company objects "owned" by SomeotherModel and it needs to know which one changed then you can pass the changed object as part of the trigger event. Note the added colons on the Symbols Company>>companyName: aString companyName := aString. self trigger: #companyNameChanged: with: self SomeotherModel>>update: aCompany self halt company when: #companyNameChanged: send: #update: to: viewObj The other method Bill mentions uses a ValueModel and is more complicated. Company>>initialize companyName := String new asValue Company>>companyName ^companyName value Company>>companyName: aString companyName value: aString Company>>companyNameValueHolder ^companyName SomeotherModel>>update self halt. company := Company new. viewObj := SomeotherModel new. company companyNameValueHolder when: #valueChanged send #update to: viewObj. company companyName: 'Meezon Software'. The advantage of this method is that you can share the companyNameValueHolder with other interested parties and not need any more "glue" code. Assuming (because of the name you used) that SomeotherModel is some kind of Shell containing a TextPresenter that is supposed to display a company name then you would only need the following to link them together - viewObj companyNamePresenter model: company companyNameValueHolder As in all these things the best way does really depend on what you are trying to do..... Ian |
Free forum by Nabble | Edit this page |