public static void main(String[] args) {
NikeClothFactory ncf=new NikeClothFactory();//被代理类的对象
ProxyFactory pf=new ProxyFactory(ncf);//代理类实例化,将被代理类的对象传入构造器中
pf.productCloth();
}
}
interface Clothproduct{//接口
void productCloth();
}
class NikeClothFactory implements Clothproduct{//被代理类
public void productCloth(){
System.out.println("nike make cloth");//重写方法
}
}
class ProxyFactory implements Clothproduct{//代理类
Clothproduct cp;//被代理类的对象
public ProxyFactory(Clothproduct cp){
this.cp=cp;
}
@Override
public void productCloth() {
System.out.println("proxy factory");
cp.productCloth();//调用被代理类的制衣方法
}
}
proxy factory
nike make cloth