Pursuit mm = new Pursuit("jiujiu"); ProxyStudent ggP = new ProxyStudent(mm); ggP.giveCole(); ggP.giveEat(); ggP.giveFlowers();
代理类:
private final FoolTarget proxy; ProxyStudent(Pursuit pursuit){ this.proxy = new FoolTarget(pursuit); } @Override public void giveFlowers() { proxy.giveFlowers(); }
实际的追求者:
private Pursuit pursuit; FoolTarget(Pursuit pursuit){ this.pursuit = pursuit; } @Override public void giveFlowers() { System.out.println(pursuit.name + "song hua"); }