V
VisionSet
I need to generate some simple events from my Model.
I'm using Observer/Observable interface/class, since I find the
PropertyChanged event framework over bulky for my needs. So the public
void update(Observable obj, Object evt) method will be used to deliver
events in the 2nd argument. The event class I have at present is as
follows:
public class ModelEvent {
public enum Type {PLACEMENT, PLUS_OTHER_EVENTS};
private final Object source;
private final Type type;
public ModelEvent(Object source, Type type) {
this.source = source;
this.type = type;
}
public Object getSource() {
return source;
}
public Type getEvent() {
return type;
}
}
I create a new event as so: new ModelEvent(this, ModelEvent.Type.PLACEMENT);
My GUI has interface references to the model to query state after receiving
an event.
I really don't want to build an elaborate event framework.
So I thought I'd rip the Observer/Observable code and bring it upto date
whilst giving type safety to the update/notifyObserver pair, replacing
Object with my ModelEvent
hence update(Object source, ModelEvent evt)
Now remains the source object, how to improve the type safety of that? In
this simple framework, I know it will be one of my model interfaces...
I suppose I can have my interfaces extend a tagging interface, but whats the
point I still could cast to the wrong Interface.
Can it be improved further? with generics?
Any other comments on my musings above?
TIA
I'm using Observer/Observable interface/class, since I find the
PropertyChanged event framework over bulky for my needs. So the public
void update(Observable obj, Object evt) method will be used to deliver
events in the 2nd argument. The event class I have at present is as
follows:
public class ModelEvent {
public enum Type {PLACEMENT, PLUS_OTHER_EVENTS};
private final Object source;
private final Type type;
public ModelEvent(Object source, Type type) {
this.source = source;
this.type = type;
}
public Object getSource() {
return source;
}
public Type getEvent() {
return type;
}
}
I create a new event as so: new ModelEvent(this, ModelEvent.Type.PLACEMENT);
My GUI has interface references to the model to query state after receiving
an event.
I really don't want to build an elaborate event framework.
So I thought I'd rip the Observer/Observable code and bring it upto date
whilst giving type safety to the update/notifyObserver pair, replacing
Object with my ModelEvent
hence update(Object source, ModelEvent evt)
Now remains the source object, how to improve the type safety of that? In
this simple framework, I know it will be one of my model interfaces...
I suppose I can have my interfaces extend a tagging interface, but whats the
point I still could cast to the wrong Interface.
Can it be improved further? with generics?
Any other comments on my musings above?
TIA