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() {
// 通用預(yù)檢測(cè)
preCheck(payWay);
// 不同支付方式單獨(dú)特殊處理模塊
importOuterGildeByExcelFile(descInfo);
// 通用后檢測(cè)
afterCheck(payWay);
}
public void preCheck(Integer payWay) {
String payName = "";
switch (payWay) {
case 1:
payName = "支付寶";
break;
case 4:
payName = "微信";
break;
case 5:
payName = "銀聯(lián)";
break;
default:
payName = "銀聯(lián)";
break;
}
System.out.println(payName + "支付:預(yù)檢測(cè)開(kāi)始...");
}
public void afterCheck(Integer payWay) {
String payName = "";
switch (payWay) {
case 1:
payName = "支付寶";
break;
case 4:
payName = "微信";
break;
case 5:
payName = "銀聯(lián)";
break;
default:
payName = "銀聯(lián)";
break;
}
System.out.println(payName + "支付:后檢測(cè)開(kāi)始...");
}
public abstract void importOuterGildeByExcelFile(String descInfo);
}
3:三個(gè)具體子類(lèi)方法
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:測(cè)試
public class TestTemplate {
public static void main(String[] args) {
AliFileImportImpl aliFileImport = new AliFileImportImpl(1, "導(dǎo)入支付寶外部文件核心邏輯", "AliFileImportImpl.");
aliFileImport.doImportGlide();
WechatFileImportImpl wechatFileImport = new WechatFileImportImpl(4, "導(dǎo)入微信外部文件核心邏輯", "WechatFileImportImpl.");
wechatFileImport.doImportGlide();
YinLianFileImportImpl duxiaomFileImport = new YinLianFileImportImpl(5, "導(dǎo)入銀聯(lián)外部文件核心邏輯", "DuxiaomFileImportImpl.");
duxiaomFileImport.doImportGlide();
}
}