3358 www.Sina.com/https://github.com/1711680493
我要进入github
有关设计模式的详细信息,请进入我的设计模式专栏
代理模式代理模式不是23设计模式之一。
和战略模型很相似。
它有三个作用:
抽象任务角色委托者角色特定任务角色委托模式是将任务发送到委托者角色,委托者角色委托特定任务角色
代理模式向外部隐藏具体实现,只向外部暴露代理者的作用
github地址:
委派模式和策略模式不同的是,委派者角色和具体任务角色都要继承/实现抽象任务角色
代码实现/** *代理模式* @ authorshendiahref=' Tencent ://add contact/from id=45 from subid=1sub cmd=all uin=17116804999 p .执行(b ); p.exec (? 什么事? ' ); }}/** *抽象任务的作用* @ authorshendiahref=' Tencent ://add contact/from id=45 from subid=1sub cmd=all uin=1711680444 * @ from id=45 from subid=1sub cmd=all uin=1711680493 ' QQ/a* @ param name委托名*/void exec (字符串名称); }/** *委托人* @ authorshendiahref=' Tencent ://add contact/from id=45 from subid=1sub cmd=all uin=1711680493 ' QQ classdelegateplayerimplementsdelegateabstract { @ overridepublicvoidexec (string name ) /委托他人//在此使用HashMap创建}elseif(b ).equals (name ) ) {d=new DelegateB ); } else {System.out.println ('我是委托人,没有此角色: ' name ); (if ) d!=null(d.exec ) name; }}/** *具体角色a * @ authorshendiahref=' Tencent ://add contact/from id=45 from subid=1sub cmd=all uin=1711680493 classdelegateaimplementsdelegateabstract { @ } }/* * *具体角色b * @ authorshendiahref=' Tencent ://add contact/from id=45 from subid=1sub cmd=all uin=1711680493 ' QQ/a* @ 1.0 */classdelegatebimplementsdelegateabstract { @ }