public class Girl {
private String name;
public Girl() {
}
public Girl(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public interface IGiveGift {
void giveDolls();
void giveFlowers();
void giveChocolate();
}
public class Pursuit implements IGiveGift {
private Girl girl;
public Pursuit() {
}
public Pursuit(Girl girl) {
this.girl = girl;
}
@Override
public void giveDolls() {
System.out.println(girl.getName() + " 送你洋娃娃");
}
@Override
public void giveFlowers() {
System.out.println(girl.getName() + " 送你鲜花");
}
@Override
public void giveChocolate() {
System.out.println(girl.getName() + " 送你巧克力");
}
}
public class Proxy implements IGiveGift {
private Pursuit pursuit;
public Proxy(Girl girl) {
pursuit = new Pursuit(girl);
}
@Override
public void giveDolls() {
pursuit.giveDolls();
}
@Override
public void giveFlowers() {
pursuit.giveFlowers();
}
@Override
public void giveChocolate() {
pursuit.giveChocolate();
}
}
public class Main {
public static void main(String[] args) {
Girl girl = new Girl("女神");
Proxy proxy = new Proxy(girl);
proxy.giveDolls();
proxy.giveFlowers();
proxy.giveChocolate();
}
}
运行结果:
女神 送你洋娃娃
女神 送你鲜花
女神 送你巧克力