次のインターフェースを検討してください。
public interface ThirdPartyApiHandler {
public OperationResult doOperation(OperationInput input);
public static class OperationResult {
//members of OpeationResult. metrics after file processing
private int successfulRecords;
private int failedRecords;
}
public static class OperationInput {
//implementations call third party API to process this file.
private String inputBatchFile;
}
//Constant which would be same across all implementations.
public static final int GLOBAL_CONSTANT = 1;
}
上記のインターフェースは悪いデザインですか?
OperationResult
OperationInput
静的クラスとして定義されています。それらは実装によってのみ使用され、他の場所では使用されません。ここに見られる利点は、これら 2 つのクラス用に個別のファイルを作成する必要がないことです。また、親クラスの名前空間も取得します。定数インターフェイスについて読みました。ただし、この場合、すべての実装で同じになるようにバインドされ、それらの実装で使用される通常のインターフェイスで定数を定義しています。
私はこのパターンを初めて使用しているので、提案を得たいと思っていました。