An interface with different method parameters

you could make an operand-object

public interface Operation {

public int Add(Operand o);

}

or

public interface Operation {

 public int Add(Operand... o);

}

in this case you are not using the same interface, but you can create an hereditary system in which some parameters are automatically inserted:

public class CLASSA{
     public int Add(int id,String name){
         //something
     }
}

public class CLASSB extends CLASSA{
     public int Add(String name){
         super.Add(this.FIXED_ID, name);
         //something
     }
}

public class OPERATION extends CLASSA{
     public int Add(){
         super.Add(this.FIXED_ID, this.FIXED_NAME);
         //something
     }
}

A few points worth mentioning regarding the other answers:

  • Having and interface with multiple function implementation (one for each set of arguments) violates the interface segregation principle.
  • Making the class ignore the unused arguments violates the Liskov substitution principle.

My suggestion would be to implement something like the Command pattern. To decouple the command implementation from its implementations is precisely its intent.


Two solutions
Either define two methods in the interface:

public interface Operation {

public int addName(String name);
public int addIdName(int id, String name);

}

or use a generic paramter

public interface Operation {

    public int add(HashMap<String,String> keyValueParams);
}

But for Operations this should work different.