作用:为其它对象提供一种代理,以控制外界对该对象的访问
静态代理
代码:
/**
* 代理对象(Proxy) 和 被代理对象(Target) 的共同接口
* @author lyn
* "出租" 的行为
*/
public interface ICanLease {
public void lease();
}
/**
* 房子的主人 (具有把房子出租出去的行为)
* @authorlyn
*/
public class Landlord implements ICanLease{
@Override
public void lease() {
System.out.println("房子的主人把房子出租出去...");
}
}
/**
* 万恶的房产中介 (同样具有把房子出租出去的行为)
* @author lyn
*
*/
public class LandlordProxy implements ICanLease{
private ICanLease target; //被代理的对象(即真正房子的主人)
public LandlordProxy(ICanLease target){
this.target =