J
Jason Cavett
So, I am currently using Observer/Observable pattern in quite a few
spots in an application I'm designing. It works great and makes
designing the entire application fairly pain-free. There's just one
question I had about part of the system that seems a
little...clunky...
When my Observable object notifies the Observer object, there are many
ways the Observer object can react depending on what changed in the
Observable object. As such, I use...
observableObject.setChanged();
observableObject.notifyObservers(SOME_STATIC_FINAL_STRING_HERE);
The Observer object then implements update(Observable o, Object arg).
Currently, I am donig an if/else comparison against the arg object so
I know exactly what to update. This seems *somewhat* clunky, though,
because some of the Observers get quite a long list of if/else's in
their update method.
Is this the right way to go about it? Is there something better I
could be doing?
Thanks
spots in an application I'm designing. It works great and makes
designing the entire application fairly pain-free. There's just one
question I had about part of the system that seems a
little...clunky...
When my Observable object notifies the Observer object, there are many
ways the Observer object can react depending on what changed in the
Observable object. As such, I use...
observableObject.setChanged();
observableObject.notifyObservers(SOME_STATIC_FINAL_STRING_HERE);
The Observer object then implements update(Observable o, Object arg).
Currently, I am donig an if/else comparison against the arg object so
I know exactly what to update. This seems *somewhat* clunky, though,
because some of the Observers get quite a long list of if/else's in
their update method.
Is this the right way to go about it? Is there something better I
could be doing?
Thanks