基于Java的界面布局DSL的設計與實現[4]
關鍵字:
java隨著更多基本原子組件的編寫,會發現 in 和 at 方法在很多組件中都重復出現,此時可以把它們提取到一個抽象基類中。這里這樣寫是為了清楚起見。
下面我們來看看 Empty 組件,beside 和 above 組合子的實現方法,它們都很簡單。
public class Empty implements Component {
public Component at(int x,int y,int width,int height) {
return this;
}
public Component in(Container {
return this;
}
}
Empty 只是起到了一個布局空間占位的作用。beside 和 above 的實現如下:
原文轉自:http://www.anti-gravitydesign.com