public class ccuyw {
public static void main(String[] args) {
Phone w=new Phone();
fabricate f=new fabricate(w);
f.produce();
}
}
//代理访问类,进行一些控制。
class fabricate implements Workshop{
private Phone phone;
public fabricate(){}
public fabricate(Phone workshop){
this.phone=workshop;
}
public void produce(){
long s=System.currentTimeMillis();
phone.produce();//本体类正在运行
long s1=System.currentTimeMillis();
System.out.println("耗时"+(s1-s)+"毫秒");
}
}
//接口
interface Workshop{
public void produce();
}
//本体类
class Phone implements Workshop{
@Override
public void produce() {
for (int i=0;i<1000;i++) {
System.out.println("生产手机..................");
}
}
}