public class ProxyDemo {
public static void main(String[] args) {
Person p = new Person("阿健");
Matchmaker m = new Matchmaker(p);
m.miai();
}
}
interface Subject{
public void miai();
}
// 被代理类
class Person implements Subject{
private String name;
public Person(String name){
this.name = name;
}
@Override
public void miai() {
// TODO Auto-generated method stub
System.out.println(name+"正在相亲中...");
}
}
// 代理类
class Matchmaker implements Subject{
private Subject target;
public Matchmaker(Subject target){
this.target = target;
}
private void before(){
System.out.println("准备工作!");
}
private void after(){
System.out.println("相亲后的工作!");
}
@Override
public void miai() {
// TODO Auto-generated method stub
before();
target.miai();
after();
}
}