Design | example | source code
Using System;
Using System.Collections;
Product
public class Computer
{
private string Type;
Private Hashtable info=new Hashtable ();
Public Computer (String type)
{
Type=type;
Console. WriteLine ("Conputer" +type+ "is builded!");
}
public string this[string key]
{
Get
{
Return (string) Info[key];
}
Set
{
Info[key]=value;
}
}
public void Show ()
{
Console. WriteLine ("This is a computer of" +type+ ":");
Console. WriteLine ("" +info["CPU"));
Console. WriteLine ("" "+info[" Ram "]);
}
}
Builder
Public abstract class Builder
{
protected Computer Computer;
Public Computer Computpter
{
Get
{
return computer;
}
}
Public Builder (String type)
{
Computer=new computer (type);
}
Abstract public void buildcpu ();
Abstract public void Builderram ();
}
public class Macbuilder:builder
{
Public Macbuilder (String type): Base (Type)
{}
public override void Buildcpu ()
{
computer["CPU"]= "MACCPU";
}
public override void Builderram ()
{
computer["Ram"]= "MACCPU";
}
}
public class Pcbuilder:builder
{
Public Pcbuilder (String type): Base (Type)
{}
public override void Buildcpu ()
{
computer["CPU"]= "PCCPU";
}
public override void Builderram ()
{
computer["Ram"]= "PCCPU";
}
}
public class Worker
{
public void construct (Builder Builder)
{
Builder. Buildcpu ();
Builder. Builderram ();
}
}
public class CEO
{
public static void Main ()
{
Try
{
Worker worker=new Worker ();
Builder pcbuilder=new pcbuilder ("Pc");
Builder macbuilder=new macbuilder ("Mac");
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.