不想再原有的代码中更改业务,使用静态代理模式
package com.wyl.demo01;
//租房
public interface Rent {
public void rent();
}
package com.wyl.demo01;
//房东
public class Host implements Rent{
@Override
public void rent() {
System.out.println("房东要出租房子");
}
}
package com.wyl.demo01;
//代理
public class Proxy implements Rent{
private Host host;
public Proxy(Host host) {
this.host = host;
}
public Proxy() {
}
@Override
public void rent() {
host.rent();
seeHouse();
fare();
}
//看房
public void seeHouse(){
System.out.println("中介带我看房子");
}
//中介费
public void fare(){
System.out.println("收中介费");
}
}
package com.wyl.demo01;
//我
public class Client {
public static void main(String[] args) {
Host host = new Host();
Proxy proxy = new Proxy(host);
proxy.rent();
}
}



