架构师训练营 第三周作业

用户头像
郎哲158
关注
发布于: 2020 年 10 月 04 日
架构师训练营 第三周作业



以下是组合模式的代码,在写的时候有几处有疑问,望解答:

  1. 重复出现的button及用户名和密码是否可以用工厂模式写?

  2. 忘记用户名和密码,是否可以用继承方式,忘记密码多一个 Link

  3. 密码框和文本框,也有相似之处 用组合实现?

  4. 以上算不上算过渡设计



import java.awt.*;
public class Main {
public static void main(String[] args) {
WinForm winForm = new WinForm ("WINDOWS窗口");
winForm.print ();
}
}
class Log {
public static void print(String arg, String name) {
System.out.println ("print " + arg + "(" + name + ")");
}
}
class WinForm {
private String name;
private Logo logo;
private Button loginButton;
private Button registerButton;
private Frame frame;
public WinForm(String name) {
this.name = name;
logo = new Logo ("LOGO图片");
loginButton = new Button ("登陆");
registerButton = new Button ("注册");
frame = new Frame ("Frame1");
}
public void print() {
Log.print (this.getClass ().getName (), name);
logo.print ();
loginButton.print ();
registerButton.print ();
frame.print ();
}
}
class Lable {
private String name;
public Lable(String name) {
this.name = name;
}
public void print() {
Log.print (this.getClass ().getName (), this.name);
}
}
class LinkLable {
private String name;
public LinkLable(String name) {
this.name = name;
}
public void print() {
Log.print (this.getClass ().getName (), this.name);
}
}
class Frame {
private String name;
private Lable userName;
private TextBox userNameTextBox;
private Lable password;
private PasswordBox passwordBox;
private CheckBox checkBox;
private TextBox rememberUsername;
private LinkLable forgotPassword;
public Frame(String name) {
this.name = name;
userName = new Lable ("用户名");
userNameTextBox = new TextBox ("文本框");
password = new Lable ("密码");
passwordBox = new PasswordBox ("密码框");
checkBox = new CheckBox ("复选框");
rememberUsername = new TextBox ("记住用户名");
forgotPassword = new LinkLable ("忘记密码");
}
public void print() {
Log.print (this.getClass ().getName (), name);
userName.print ();
userNameTextBox.print ();
password.print ();
passwordBox.print ();
checkBox.print ();
rememberUsername.print ();
forgotPassword.print ();
}
}
class TextBox {
private String name;
public TextBox(String name) {
this.name = name;
}
public void print() {
Log.print (this.getClass ().getName (), this.name);
}
}
class PasswordBox {
private String name;
public PasswordBox(String name) {
this.name = name;
}
public void print() {
Log.print (this.getClass ().getName (), this.name);
}
}
class CheckBox {
private String name;
public CheckBox(String name) {
this.name = name;
}
public void print() {
Log.print (this.getClass ().getName (), this.name);
}
}
class Button {
public Button(String name) {
this.name = name;
}
private String name;
public void print() {
Log.print (this.getClass ().getName (), this.name);
}
}
class Logo {
private String name;
public Logo(String name) {
this.name = name;
}
public void print() {
Log.print (this.getClass ().getName (), this.name);
}
}





用户头像

郎哲158

关注

还未添加个人签名 2017.12.20 加入

还未添加个人简介

评论

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