private void t() {
viewGroup viewGroup=new viewGroup("layout");
viewGroup.addView(new view("image"));
viewGroup.addView(new view("txt"));
viewGroup viewGroup1=new viewGroup("frame");
viewGroup1.addView(viewGroup);
viewGroup1.addView(new view("list"));
Log.i(TAG, "t: "+viewGroup1.list.toString());
}
abstract class viewElement{
protected List<viewElement> list=new ArrayList<>();
protected String name;
public String getName() {
return name;
}
public viewElement(String name) {
this.name = name;
}
public abstract void addView(viewElement view);
public abstract void removeView(viewElement view);
}
class view extends viewElement{
public view(String name) {
super(name);
}
@Override
public void addView(viewElement view) {
Log.i(TAG, "addView: no support");
}
@Override
public void removeView(viewElement view) {
Log.i(TAG, "removeView: no support");
}
@Override
public String toString() {
return "view{" +
"name='" + name + '\'' +
'}';
}
}
class viewGroup extends viewElement{
public viewGroup(String name) {
super(name);
}
@Override
public void addView(viewElement view) {
list.add(view);
}
@Override
public void removeView(viewElement view) {
list.remove(view);
}
@Override
public String toString() {
return "viewGroup{" +
"name='" + name + '\'' +
'}';
}
}
android 节点组合模式 DOM模式
最新推荐文章于 2023-04-15 17:58:52 发布