考虑以下界面。
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
定义为静态类。它们只会被实现使用,而不是其他任何地方。我在这里看到的优势是 - 我不必为这两个类创建单独的文件。他们还获得父类的命名空间。我已阅读有关常量接口的信息。但在这种情况下,我在普通接口中定义常量,这些常量在所有实现中都是相同的,并且将在这些实现中使用。
我第一次使用这种模式,所以想得到建议。