首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件开发 >

设计方式-proxy

2012-10-09 
设计模式-proxySpring的Aop和?Struts个拦截器,动态代理模式就是执行某方法,之前或之后干些什么!!!首先是简

设计模式-proxy

Spring的Aop和?Struts个拦截器,动态代理模式就是执行某方法,之前或之后干些什么!!!
首先是简单的Aspect接口

?设计方式-proxy
    ?设计方式-proxy
      ?设计方式-proxy
        ?设计方式-proxy
          public?interface?Student?{ ??????public?void?sayHello(); ?? } ????import?org.aspect.Aspect; ?? ??public?class?StudentAspectOne?implements?Aspect?{ ?? ??????@Override?? ????public?void?doAfter()?{ ?? ????????System.out.println("do?After?One"); ?? ???????? ??????} ????????@Override?? ????public?void?doBefore()?{ ?? ????????System.out.println("do?Before?One"); ?? ???????? ??????} ????} ????import?org.aspect.Aspect; ?? ????public?class?StudentAspectTwo?implements?Aspect{ ?? ????@Override?? ????public?void?doAfter()?{ ?? ????????System.out.println("do?After?Two"); ?? ???????? ??????} ????????@Override?? ????public?void?doBefore()?{ ?? ????????System.out.println("do?Before?Two"); ?? ???????? ??????} ??} ????public?class?StudentImpl?implements?Student?{ ?? ??????@Override?? ????public?void?sayHello()?{ ?? ????????System.out.println("Student"); ?? ????} ????} ????import?java.util.ArrayList; ?? import?java.util.List; ?? ??import?org.aspect.Aspect; ?? import?org.aspect.DynamicProxyFactory; ?? ??public?class?Test?{ ?? ??????public?static?void?main(String[]?args)?{ ?? ???????? ??????????List<Aspect>?aspectList?=?new?ArrayList<Aspect>(); ?? ???????? ??????????aspectList.add(new?StudentAspectOne()); ?? ????????aspectList.add(new?StudentAspectTwo()); ?? ????????Student?s?=?(Student)DynamicProxyFactory.newInstance(new?StudentImpl(),?aspectList); ?? ????????s.sayHello(); ??????} ????}??



        执行Test,控制台返回

        do Before One
        do Before Two
        Student
        do After Two
        do After One

热点排行