Architecture Phase1 Week3:HomeWork
单例模式设计,使用默认方式进行创建提高单例执行效率。
public interface UIComponent{
public abstract void draw();
public hashmap containers=new hashmap();
public abstract size getSize();
public abstract void setSize();
}
public class button implements UIComponent{
public void draw(){
println("Button");
}
}
public class label implements UIComponent{
public void draw(){
println("Button");
}
}
public class Container implements UIComponent{
public void addComponent(UIComponent component){
containers.push_back(component);
}
public void draw(){
for(int i=0;i<containers.length;i++){
containers[i].draw();
}
}
}
public class window extends Container{
public void draw(){
println("draw window");
base.draw)();
}
}
版权声明: 本文为 InfoQ 作者【phylony-lu】的原创文章。
原文链接:【http://xie.infoq.cn/article/a90082cf6faf7e2ad6854544c】。文章转载请联系作者。
评论