使用接口组织枚举

来源:互联网 发布:广州恒大淘宝 编辑:程序博客网 时间:2024/06/08 17:37



package com.chapter19;/** * 功能描述:使用接口方式组织枚举 * 请按模块新建enum或者在现有enum中新增常量;后续可以按照领域进行编码组织 */public interface ErrorCodes {/** * 基本操作错误模块 * @author kinsey */enum BasicError implements ErrorCodes{BASIC_ERROR("BEC000001","失败"),INSERT_ERROR("BEC00002","插入失败"),DELETE_ERROR("BEC00003","删除失败"),UPDATE_ERROR("BEC00004","更新失败"),SELECR_ERROR("BEC00002","查找失败"); private String errorCode; private String errorMsg;  private BasicError(String errorCode,String errorMsg) { this.errorCode = errorCode; this.errorMsg = errorMsg; }  public String getErrorCode(){ return errorCode; }  public String getErrorMsg(){ return errorMsg; }  @Overridepublic String toString() {// TODO Auto-generated method stubreturn super.toString();}}/** * 参数错误模块 * @author kinsey */enum ParaError implements ErrorCodes{PARA_ERROR("PE000001","参数错误"),PARA_NULL("PE00002","参数为空"),PARA_MISSING("PE00003","缺少参数");private String errorCode;private String errorMsg;private ParaError(String errorCode,String errorMsg) {this.errorCode = errorCode;this.errorMsg = errorMsg;}public String getErrorCode(){return errorCode;}public String getErrorMsg(){return errorMsg;}}   }

package com.chapter19;import com.chapter19.ErrorCodes.BasicError;public class TestMain {public static void main(String[] args) {BasicError err = ErrorCodes.BasicError.BASIC_ERROR;System.out.println(err.getErrorCode() + ":" + err.getErrorMsg());}}




原创粉丝点击