1:模板接口
public interface OuterGlideImportInterface {
public void doImportGlide();
}
2:模板抽象方法
public abstract class AbstractOuterGlideImportCommand implements OuterGlideImportInterface {
public Integer payWay;
public String descInfo;
public AbstractOuterGlideImportCommand(Integer payWay, String descInfo) {
this.payWay = payWay;
this.descInfo = descInfo;
}
@Override
public void doImportGlide() {
// 通用预检测
preCheck(payWay);
// 不同支付方式单独特殊处理模块
importOuterGildeByExcelFile(descInfo);
// 通用后检测
afterCheck(payWay);
}
public void preCheck(Integer payWay) {
String payName = "";
switch (payWay) {
case 1:
payName = "支付宝";
break;
case 4:
payName = "微信";
break;
case 5:
payName = "银联";
break;
default:
payName = "银联";
break;
}
System.out.println(payName + "支付:预检测开始...");
}
public void afterCheck(Integer payWay) {
String payName = "";
switch (payWay) {
case 1:
payName = "支付宝";
break;
case 4:
payName = "微信";
break;
case 5:
payName = "银联";
break;
default:
payName = "银联";
break;
}
System.out.println(payName + "支付:后检测开始...");
}
public abstract void importOuterGildeByExcelFile(String descInfo);
}
3:三个具体子类方法
public class AliFileImportImpl extends AbstractOuterGlideImportCommand {
public String preDescInfo;
public AliFileImportImpl(Integer payWay, String descInfo, String preDescInfo) {
super(payWay, descInfo);
this.preDescInfo = preDescInfo;
}
@Override
public void importOuterGildeByExcelFile(String descInfo) {
System.out.println(preDescInfo + descInfo);
}
}
public class WechatFileImportImpl extends AbstractOuterGlideImportCommand {
public String preDescInfo;
public WechatFileImportImpl(Integer payWay, String descInfo, String preDescInfo) {
super(payWay, descInfo);
this.preDescInfo = preDescInfo;
}
@Override
public void importOuterGildeByExcelFile(String descInfo) {
System.out.println(preDescInfo + descInfo);
}
}
public class YinLianFileImportImpl extends AbstractOuterGlideImportCommand {
public String preDescInfo;
public YinLianFileImportImpl(Integer payWay, String descInfo, String preDescInfo) {
super(payWay, descInfo);
this.preDescInfo = preDescInfo;
}
@Override
public void importOuterGildeByExcelFile(String descInfo) {
System.out.println(preDescInfo + descInfo);
}
}
4:测试
public class TestTemplate {
public static void main(String[] args) {
AliFileImportImpl aliFileImport = new AliFileImportImpl(1, "导入支付宝外部文件核心逻辑", "AliFileImportImpl.");
aliFileImport.doImportGlide();
WechatFileImportImpl wechatFileImport = new WechatFileImportImpl(4, "导入微信外部文件核心逻辑", "WechatFileImportImpl.");
wechatFileImport.doImportGlide();
YinLianFileImportImpl duxiaomFileImport = new YinLianFileImportImpl(5, "导入银联外部文件核心逻辑", "DuxiaomFileImportImpl.");
duxiaomFileImport.doImportGlide();
}
}