设计模式
程序员文章站
2022-05-17 19:40:00
...
单例+工厂+模板模式混用
1.抽象类
public class QueryBalanceBg extends BaseHF{ @Override public String execute(Map<String, Object> map) throws Exception { } }
2.继承抽象类实现模板模式
public abstract class BaseHF extends BaseLog{ public abstract String execute(Map<String, Object> map) throws Exception; }
3.工厂模式+单例模式
public class BaseHFFactory { private static final String QUERYBALANCEBG = "QueryBalanceBg"; private BaseHFFactory(){} private static BaseHFFactory baseHFFactory; public static BaseHFFactory getInstance(){ if(baseHFFactory == null){ baseHFFactory = new BaseHFFactory(); } return baseHFFactory; } public BaseHF getBaseHF(String name){ if(name.isEmpty()){ return null; } if(QUERYBALANCEBG.equals(name)){ return new QueryBalanceBg(); } return null; } }