架构师 week3 作业

发布于: 2020 年 06 月 24 日

1.手写单列模式

2.写代码实现组合模式

代码:

public interface Component {

void add(Componet component);

void remove(Componet component);

List<Component> getComponent();

}

在抽象类里面实现基础公共方法

public abstract class AbstractComponent implements Component{

protected abstract void add(Componet component);

protected abstract void remove(Componet component);

protected abstract List<Component> getComponent();

}

Pictrue类不是容器类,add和remove不做具体实现

public class Picture exents AbstractComponent {

@Override

public void add (Componet component){ }

@Override

public void remove (Componet component){ }

@Override

public List<Component> getComponent (){ return null; }

}

Lable类

public class Lable exents AbstractComponent {

@Override

public void add (Componet component){ }

@Override

public void remove (Componet component){ }

@Override

public List<Component> getComponent (){ return null; }

}

Button类

public class Button exents AbstractComponent {

@Override

public void add (Componet component){ }

@Override

public void remove (Componet component){ }

@Override

public List<Component> getComponent (){ return null; }

}

TextBox类

public class TextBox exents AbstractComponent {

@Override

public void add (Componet component){ }

@Override

public void remove (Componet component){ }

@Override

public List<Component> getComponent (){ return null; }

}

PasswordBox类

public class PasswordBox exents AbstractComponent {

@Override

public void add (Componet component){ }

@Override

public void remove (Componet component){ }

@Override

public List<Component> getComponent (){ return null; }

}

CheckBox类

public class CheckBox exents AbstractComponent {

@Override

public void add (Componet component){ }

@Override

public void remove (Componet component){ }

@Override

public List<Component> getComponent (){ return null; }

}

LinkLable类

public class LinkLable exents AbstractComponent {

@Override

public void add (Componet component){ }

@Override

public void remove (Componet component){ }

@Override

public List<Component> getComponent (){ return null; }

}

WinFrom类 顶级容器类

public class WinFrom exents AbstractComponent {

private List<Component> components;

@Override

public void add (Componet component){

components.add(component);

}

@Override

public void remove (Componet component){

components.remove(component);

}

@Override

public List<Component> getComponent (){ return components; }

}

Frame类容器类

public class Frame exents AbstractComponent {

private List<Component> components;

@Override

public void add (Componet component){

components.add(component);

}

@Override

public void remove (Componet component){

components.remove(component);

}

@Override

public List<Component> getComponent (){ return components; }

}

public class runApp {

private WinForm form1 = new WinForm("Window窗口");

private Picture pic1 = new Picture("Logo图片");

private Button bt1 = new Button("登录");

private Button bt2 = new Button("注册");

private Frame frame1 = new Frame("frame1");

private Lable lable1 = new Lable("用户名");

private TextBox textBox1 = new TextBox("文本框");

private Lable lable2 = new Lable("密码");

private PasswordBox pwdBox1 = new PasswordBox("密码框");

private CheckBox checkBox1 = new CheckBox("复选框");

private TextBox textBox2 = new TextBox("记住用户名");

private LinkLable linkLable = new LinkLable("忘记密码");

public void static main(String [] args) {

frame1.add(lable1);

frame1.add(textBox1);

frame1.add(lable2);

frame1.add(pwdBox1);

frame1.add(checkBox1);

frame1.add(textBox2);

frame1.add(linkLable);

form1.add(pic1);

form1.add(bt1);

form1.add(bt2);

form1.add(frame1);

//显示界面

form1.show();

}

}

总结:这个如果做过Winform开发就明白了,通过组合模式把复杂业务呈现在From界面上

用户头像

平淡人生

关注

还未添加个人签名 2018.11.05 加入

还未添加个人简介

评论

发布
暂无评论
架构师week3作业