10.1静态代理
角色分析:
-
抽象角色 : 一般使用接口或者抽象类来实现
-
真实角色 : 被代理的角色
-
代理角色 : 代理真实角色 ; 代理真实角色后 , 一般会做一些附属的操作 .
-
客户 : 使用代理角色来进行一些操作 .
代码步骤
接口
package com.sqt.demo1;
public interface Rent {
public void rent();
}
真实角色
package com.sqt.demo1;
public class Host implements Rent{
@Override
public void rent() {
System.out.println("房东要出租房子!");
}
}
代理
package com.sqt.demo1;
public class Proxy implements Rent{
private Host host;
public Proxy() {
}
public Proxy(Host host) {
this.host = host;
}
//中介带你看房
public void seeHouse(){
System.out.println("中介带你看房子!");
}
//收中介费
public void fare(){
System.out.println("1000000元中介费!");
}
//签合同
public void hetong(){
System.ou