委托模式委托模式(DelegatePattern)的基本功能是负责调用任务和分配任务。它与代理模式非常相似。在特殊情况下,静态代理可以认为是全功率代理。然而,代理模式侧重于过程,而委托模式侧重于结果。 Spring中广泛使用委托模式,常用的DispatcherServlet其实就是使用了委托模式。
public class Leader { private Map empList=new HashMap(); public Leader(){ empList.put('加密',new EmpA()); empList.put('schema',new EmpB()); } public void 做(String command){ empList.get(command).doing(command); }} 是一种通过中间类选择要执行的特定类的方法。代码:https://github.com/zhucl1006/java-pattern-std
标题:设计模式 委托,委派模式和策略模式
链接:https://www.52funs.com/news/sypc/11452.html
版权:文章转载自网络,如有侵权,请联系删除!