java实现静态代理

import javax.sound.sampled.Port; interface Person { public void sayHello() ; } class Student implements Person { public void sayHello() { System.out.println( "学生向大家Say Hello" ) ; } } //使用静态代理,最大的问题,代理类只能为一个接口服务,扩展性不行 class ProxyPerson implements Person { private Person per ; public ProxyPerson( Person per ) { this.per = per ; } public void sayHello() { System.out.println( "Say Hello前先让校长讲两句" ) ; this.per.sayHello() ; System.out.println( "Say Hello后再让校长臭得色几句" ) ; } } public class Test { public static void main( String[] args ) { Person per = new ProxyPerson( new Student() ) ; per.sayHello() ; } }

你可能感兴趣的:(java,String,Class,扩展,import)