java 接口类定义常量_Java接口 – 普通接口中的常量和静态类

考虑以下界面.

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定义为静态类.它们仅用于实现而不是其他任何地方.我在这里看到的优点是 – 我不必为这两个类创建单独的文件.他们也获得了父类的命名空间.

>我已阅读有关常量接口的信息.但在这种情况下,我在普通接口中定义常量,这些常量在所有实现中都必须相同,并且将在这些实现中使用.

我是第一次使用这种模式,所以想得到建议.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值