import  java.lang.reflect.Method;
import  java.lang.reflect.InvocationHandler;
import  java.lang.reflect.Proxy;
interface Business{
	public void renting();
}
class Lessee implements Business{
	public void renting(){
		System.out.println("Renting a house.");
	}
}
class  DynamicProxyHandler  implements  InvocationHandler   {
private Object obj;
  public Object invoke(Object proxy, Method method, Object[] args)  throws  Throwable {
    System.out.println("Charging");
    method.invoke(obj,args);                   //利用invoke()方法执行method对象代表的方法
    return  null ;
  }
   public Object getProxy(Object target){
      obj = target;
return Proxy.newProxyInstance(target.getClass().getClassLoader(),
target.getClass().getInterfaces(),this);
}
}
public class Example12_9{
	public static void  main(String[] args){
		DynamicProxyHandler handler = new DynamicProxyHandler();
		Business business = (Business)handler.getProxy(new Lessee());
		business.renting();
	}
}

 
