架构师训练营第 1 期 - 第三周作业提交
发布于: 2020 年 10 月 04 日
作业1
请在草稿纸上手写一个单例模式的实现代码,拍照提交作业。
忽略字丑的问题,谢谢.
作业2
2. 请用组合设计模式编写程序,打印输出图 1 的窗口,窗口组件的树结构如图 2 所示,打印输出示例参考图 3。
// 接口public interface Component { public void draw();}// 容器类import java.util.ArrayList;import java.util.List;public class BasicComponent implements Component { private String name; private List<Component> subComponent = new ArrayList<>(); public BasicComponent(String name) { this.name = name; } public void addSubComponent(Component sub) { subComponent.add(sub); } @Override public void draw() { System.out.println("print " + name); for (Component c : subComponent) { c.draw(); } }}// 主函数public class Application { public static void main(String[] args) { BasicComponent winForm = new BasicComponent("WinForm(Windows 窗口)"); Component picture = new BasicComponent("Picture(Logo 图片)"); Component btnLogin = new BasicComponent("Button(登录)"); Component btnReg = new BasicComponent("Button(注册)"); BasicComponent frameLoginWrapper = new BasicComponent("Frame(Frame1)"); Component lblUsername = new BasicComponent("Label(用户名)"); Component txtUsername = new BasicComponent("TextBox(文本框)"); Component lblPassword = new BasicComponent("Label(密码)"); Component txtPassword = new BasicComponent("PasswordBox(密码框)"); Component checkRemember = new BasicComponent("CheckBox(复选框)"); Component lblRemember = new BasicComponent("TextBox(记住用户名,应该是个 Label?)"); Component linkLabelRemember = new BasicComponent("linkLabel(忘记密码)"); frameLoginWrapper.addSubComponent(lblUsername); frameLoginWrapper.addSubComponent(txtUsername); frameLoginWrapper.addSubComponent(lblPassword); frameLoginWrapper.addSubComponent(txtPassword); frameLoginWrapper.addSubComponent(checkRemember); frameLoginWrapper.addSubComponent(lblRemember); frameLoginWrapper.addSubComponent(linkLabelRemember); winForm.addSubComponent(picture); winForm.addSubComponent(btnLogin); winForm.addSubComponent(btnReg); winForm.addSubComponent(frameLoginWrapper); winForm.draw(); }}
划线
评论
复制
发布于: 2020 年 10 月 04 日 阅读数: 18
Todd-Lee
关注
还未添加个人签名 2017.10.17 加入
还未添加个人简介
评论