写点什么

架构师训练营第三周作业

用户头像
Shunyi
关注
发布于: 2020 年 10 月 04 日

作业一:

1. 请在草稿纸上手写一个单例模式的实现代码,拍照提交作业。(略过)

2. 请用组合设计模式编写程序,打印输出图 1 的窗口,窗口组件的树结构如图 2 所示,打印输出示例参考图 3。





import java.io.*;
import java.util.ArrayList;
class ViewObject{
protected String name;
public ViewObject(String name) {
this.name = name;
}
void print(){
System.out.println("print " + this.getClass().getName() + "(" + name + ")");
}
}
class ViewCombinationObject extends ViewObject{
protected ArrayList<ViewObject> subObjects = new ArrayList<ViewObject>();
public ViewCombinationObject(String name) {
super(name);
}
public void addSubViewObject(ViewObject obj) {
subObjects.add(obj);
}
public void print() {
System.out.println("print " + this.getClass().getName() + "(" + name + ")");
for (ViewObject obj : subObjects) {
obj.print();
}
}
}
class WinForm extends ViewCombinationObject{
public WinForm(String name) {
super(name);
}
}
class Picture extends ViewObject{
public Picture(String name) {
super(name);
}
}
class Button extends ViewObject{
public Button(String name) {
super(name);
}
}
class Frame extends ViewCombinationObject{
public Frame(String name) {
super(name);
}
}
class Lable extends ViewObject{
public Lable(String name) {
super(name);
}
}
class TextBox extends ViewObject{
public TextBox(String name) {
super(name);
}
}
class PasswordBox extends ViewObject{
public PasswordBox(String name) {
super(name);
}
}
class CheckBox extends ViewObject{
public CheckBox(String name) {
super(name);
}
}
class LinkLable extends ViewObject{
public LinkLable(String name) {
super(name);
}
}
public class test {
public static void main(String args[]) {
WinForm window = new WinForm("WINDOW窗口");
window.addSubViewObject(new Picture("LOGO图片"));
window.addSubViewObject(new Button("登录"));
window.addSubViewObject(new Button("注册"));
Frame frame1 = new Frame("FRAME1");
frame1.addSubViewObject(new Lable("用户名"));
frame1.addSubViewObject(new TextBox("文本框"));
frame1.addSubViewObject(new Lable("密码"));
frame1.addSubViewObject(new PasswordBox("密码框"));
frame1.addSubViewObject(new CheckBox("复选框"));
frame1.addSubViewObject(new TextBox("记住用户名"));
frame1.addSubViewObject(new LinkLable("忘记密码"));
window.addSubViewObject(frame1);
window.print();
}
}



作业二:

根据当周学习情况,完成一篇学习总结



用户头像

Shunyi

关注

还未添加个人签名 2018.09.18 加入

还未添加个人简介

评论

发布
暂无评论
架构师训练营第三周作业