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

  1. i don't think overloading method inside interface correct
  2. 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

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -