I need to implements various update methods for Observers in my project, to overload the Object argument with a specific type. So instead of using
public void update (Observable o, Object arg0){
if(arg0 instanceof Class1) ....
else if (arg0 instanceof Class2) ....
or a switch (which is a very 'C' way of working), I thought of using an interface that extends Observer and overloads the update method, like this
public interface ExtendedObserver extends Observer{
public void update (Observable obj, Class1 cls);
public void update (Observable obj, Class2 cls);
}
and then implement it into my Observers. Every different Observer will use a specific update method.
I wanted to know if it's a correct way of working, because
- I don't think overloading a method inside an interface is correct
- I still have to add the unused update methods inside every class that implements the interface.