Week 3 Assignment

用户头像
Yinan
关注
发布于: 2020 年 10 月 03 日

Thie following code is written in c#

using System;
using System.Collections.Generic;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var frame = new Frame("FRAME1");
frame.AddChildComponent(new Label("User Name:"));
frame.AddChildComponent(new TextBox("TextBox"));
frame.AddChildComponent(new Label("Password:"));
frame.AddChildComponent(new PasswordBox("TextBox"));
frame.AddChildComponent(new CheckBox("Check"));
frame.AddChildComponent(new TextBox("Remember User Name"));
frame.AddChildComponent(new LinkLabel("Forgot Password"));
var rootComponent = new WinForm("WINDOW");
rootComponent.AddChildComponent(new Picture("LOGO"));
rootComponent.AddChildComponent(new Button("Login"));
rootComponent.AddChildComponent(new Button("Register"));
rootComponent.AddChildComponent(frame);
rootComponent.RenderComponent();
}
}
abstract class PrintableComponent
{
protected readonly string title;
private IList<PrintableComponent> childComponents = new List<PrintableComponent>();
protected PrintableComponent(string title)
{
this.title = title;
}
public void RenderComponent()
{
this.Print();
foreach (var childComponent in this.childComponents)
{
childComponent.RenderComponent();
}
}
public void AddChildComponent(PrintableComponent childComponent)
{
this.childComponents.Add(childComponent);
}
protected abstract void Print();
}
class WinForm : PrintableComponent
{
public WinForm(string title) : base(title) {}
protected override void Print()
{
Console.WriteLine($"print WinForm({base.title})");
}
}
class Picture : PrintableComponent
{
public Picture(string title) : base(title) {}
protected override void Print()
{
Console.WriteLine($"print Picture({base.title})");
}
}
class Button: PrintableComponent
{
public Button(string title) : base(title) {}
protected override void Print()
{
Console.WriteLine($"print Button({base.title})");
}
}
class Frame: PrintableComponent
{
public Frame(string title) : base(title) {}
protected override void Print()
{
Console.WriteLine($"print Frame({base.title})");
}
}
class Label: PrintableComponent
{
public Label(string title) : base(title) {}
protected override void Print()
{
Console.WriteLine($"print Label({base.title})");
}
}
class TextBox: PrintableComponent
{
public TextBox(string title) : base(title) {}
protected override void Print()
{
Console.WriteLine($"print TextBox({base.title})");
}
}
class PasswordBox: PrintableComponent
{
public PasswordBox(string title) : base(title) {}
protected override void Print()
{
Console.WriteLine($"print PasswordBox({base.title})");
}
}
class CheckBox : PrintableComponent
{
public CheckBox(string title) : base(title) {}
protected override void Print()
{
Console.WriteLine($"print CheckBox({base.title})");
}
}
class LinkLabel: PrintableComponent
{
public LinkLabel(string title) : base(title) {}
protected override void Print()
{
Console.WriteLine($"print LinkLabel({base.title})");
}
}
}



asdfaskdfjlkajsdflkjaslkdjflksjdflkjsdalfkjlksdjflkjsdklafjklsadjflkjsdlakfjlkdjsfkj



用户头像

Yinan

关注

还未添加个人签名 2020.07.28 加入

还未添加个人简介

评论

发布
暂无评论
Week 3 Assignment