思想应该是 中介 思想, 就是把一个任务抽离出来, 用另一个对象以组合的方式实现. 在Spring 中以 AOP(Aspect Oriented Programming, 面向切面编程)的方式出现, 可以理解为横向扩展
public class Client {
public static void main(String[] args) {
// Host host = new Host();
// host.rent();
Host host = new Host();
Proxy proxy = new Proxy(host);
proxy.rent();
}
}
public class Host implements Rent{
@Override
public void rent() {
System.out.println("房东要出租");
}
}
public class Proxy {
private Host host;
public Proxy() {
}
public Proxy(Host h){
this.host = h;
}
public void rent() {
seeHoust();
host.rent();
hetong();
fare();
}
public void seeHoust() {
System.out.println("中介带你看房");
}
public void fare() {
System.out.println("收中介费");
}
public void hetong() {
System.out.println("签租赁合同");
}
}
public interface Rent {
void rent();
}
原文:https://www.cnblogs.com/eat-too-much/p/14820941.html