开发者

About listeners in Delegation-Event-Model pattern

开发者 https://www.devze.com 2023-03-09 00:15 出处:网络
Hi I have a question about using this pattern. When making listeners should the names of the methods be what the name of the method in the model are that triggered the event? Such as:

Hi I have a question about using this pattern. When making listeners should the names of the methods be what the name of the method in the model are that triggered the event? Such as:

(Trivial example that shows what I mean) Model:

public void setName(String name) {...}
public void setAge(int age) {...}

Listener

void nameChanged(TheEventObject event);
void ageChanged(TheEventObject event);

Or shou开发者_C百科ld this be:

void personChanged(The EventObject event);

Where the person-prefix is the name of the Model class.

To recap should the methods in the interface be for each specific method that changed some value in the model, or should it be just one that says "Hey, model changed"?


I think that easier for future is to created in the another way in some parent abstract class that each been will be delivered, you could create a instance of some class that will manage the notification kind of property change manager(observer) that would fire a event after property change.

firePropertyChange("properyName", newValue, oldValue); 

To support this you could use the java.beans.PropertyChangeEvent

Base interface for a property change observer:

void fireBeforePropertyChange(String propertyName, Object currentValue, Object newValue) throws PropertyChangeException;
void removeBeforePropertyChangeListener(BeforePropertyChangeListener beforePropertyChangeListener);
Enumeration<BeforePropertyChangeListener> getBegorePropertyChangeListeners();
0

精彩评论

暂无评论...
验证码 换一张
取 消