【发布时间】:2013-08-16 04:33:21
【问题描述】:
考虑以下界面。
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被定义为静态类。它们只会被实现使用,而不是其他任何地方。我在这里看到的优势是 - 我不必为这两个类创建单独的文件。他们还获得父类的命名空间。我已阅读有关常量接口的信息。但在这种情况下,我在普通接口中定义常量,这些常量在所有实现中都是相同的,并且将在这些实现中使用。
我是第一次使用这种模式,所以想得到建议。
【问题讨论】:
-
您的
OperationResult和OperationInput中有什么内容? -
OperationInput 包含用于调用第三方 API 的成员变量。 OperationResult 是我的包装器,它将第三方 API 结果转换为可用格式。
-
@Jitendra。你能完成你问题中的那些课程吗?以便我们能够想到合适的设计。
-
OperationResult and OperationInput are defined as static inner class. They won't be used anywhere else但如果你实现了doOperation方法。这个方法的调用者会使用这两种类型,不是吗? -
是的,我的意思是,它们只会用于这个特定接口的实现。不是任何其他不相关的类。
标签: java