namespace 工厂加工模式
{
class 加工模式
{
static void Main(string[] args)
{
Console.WriteLine("输入你想要的笔记本品牌");
string sel = Console.ReadLine();
NoteBook bb = GetNoteBook(sel);
bb.SayHello();
Console.ReadKey();
}
public static NoteBook GetNoteBook(string sel)
{
NoteBook nb = null;
switch (sel)
{
case "Lenovo":
nb = new Lenovo();
break;
case "Acer":
nb = new Acer();
break;
case "Dell":
nb = new Dll();
break;
case "IBM":
nb = new IBM();
break;
default:
break;
}
return nb;
}
}
//
public abstract class NoteBook
{
public abstract void SayHello();
}
public class Acer : NoteBook
{
public override void SayHello()
{
Console.WriteLine("我是鸿基笔记本");
}
}
public class Lenovo : NoteBook
{
private string _name;
public int Name { get; set; }
public Lenovo()
{ }
public Lenovo(string Name,int Age)
{
}
public override void SayHello()
{
Console.WriteLine("我是联想笔记本");
}
public void SayHello(string msg)
{
Console.WriteLine(msg);
}
}
public class Dll : NoteBook
{
public override void SayHello()
{
Console.WriteLine("我是Dell笔记本");
}
}
public class IBM : NoteBook
{
public override void SayHello()
{
Console.WriteLine("我是IBM笔记本");
}
}
}
Post Views: 333