以下のようにJavaインターフェイスでメソッドをオーバーロードするのは正しいですか?そしてあなたのサブクラスで必要なメソッドを使用しますか?そうでない場合は、それを行うより良い方法があります、親切に提案してください。Javaインターフェイスのオーバーロードメソッド
interface IEmployees{
public List<String> getEmployees(List<String> employees, List<String> departments);
public List<String> getEmployees(List<String> employees, String name);
}
class EmployeesByDept implements IEmployees{
public List<String> getEmployees(List<String> employees, List<String> departments){
// select employees belonging to depts in list and return.
}
public List<String> getEmployees(List<String> employees, String name){
throw new UnsupportedOperationException();
}
}
class EmployeesByName implements IEmployees{
public List<String> getEmployees(List<String> employees, List<String> departments){
throw new UnsupportedOperationException();
}
public List<String> getEmployees(List<String> employees, String name){
// select employees with name in list and return.
}
}
"それは正しい"とはどういう意味ですか? – Mena
メソッドの1つだけが許可されている場合は、インターフェイスを2つに分割します。それ以外に、インターフェイスが1つのクラスで実装されているメソッドを1つしか持たない場合は、そのインターフェイスが必要かどうかを自問するかもしれません。 – Thomas
表現する 'IEmployees' *とは何ですか?答えは本当にそれに依存します。それは:1a)すべての既知の従業員のリスト、1b)知られているすべての従業員の任意のサブセット、または2)従業員を持つ組織ですか? –