1、创建接口类
package com.lx.proxy;public interface StudentService { void study();}
2、接口实现类,具体业务处理
package com.lx.proxy;public class StudentServiceImp implements StudentService { @Override public void study() { System.out.println("day day up !"); }}
3、静态代理类
package com.lx.proxy;public class StudentProxy implements StudentService { private StudentService student; public StudentProxy(StudentService student){ this.student = student; } @Override public void study() { System.out.println("before study !"); student.study(); System.out.println("after study !"); }}
4、客户端
package com.lx.proxy;public class Client1 { public static void main(String[] args){ StudentProxy studentProxy = new StudentProxy(new StudentServiceImp()); studentProxy.study(); }}