B.java
package seven;
public class B {
public void testOrder(OrderInter order){
order.test();
}
}
OrderInter.java
package seven;
public interface OrderInter {
void test();
}
Boss.java
package seven;
public class Boss implements OrderInter {
@Override
public void test() {
// TODO Auto-generated method stub
System.out.println("老板收到相应的消息");
}
}
Secretary.java
package seven;
public class Secretary implements OrderInter {
//被代理对象
private OrderInter boss;
public Secretary(OrderInter boss){
this.boss = boss;
}
@Override
public void test() {
// TODO Auto-generated method stub
System.out.println("==========前==========");
boss.test();
System.out.println("==========后==========");
}
}
Main.java
package seven;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
OrderInter boss = new Boss();
OrderInter proxy = new Secretary(boss);
B b = new B();
b.testOrder(proxy);
}
}