Overloading inside interface in Java -
i need implements various update
methods observers
in project, overload object argument specific type. instead of using
public void update (observable o, object arg0){ if(arg0 instanceof class1) .... else if (arg0 instanceof class2) ....
or switch (which 'c' way of working), thought of using interface
extends observer
, overloads update
method, this
public interface extendedobserver extends observer{ public void update (observable obj, class1 cls); public void update (observable obj, class2 cls); }
and implement observers. every different observer use specific update method.
i wanted know if it's correct way of working, because
- i don't think overloading method inside interface correct
- i still have add unused update methods inside every class implements interface.
- there no problem in overloading method inside interface
- an interface contract mandatory implementing classes implement. if not want classes implement method. there no need include in interface well.
- so can write overloaded method in classes needed. or make abstract class implement interface , write overloaded method in it.
- this way not end of exposing unnecessary method contract other classes
Comments
Post a Comment