using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 简单工厂模式
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入笔记本品牌:");
string Brand = Console.ReadLine();
NoteBook nb = GetNoteBook(Brand);
nb.SayHello();
Console.ReadKey();
}
public static NoteBook GetNoteBook(string brand)
{
NoteBook nb = null;
switch (brand)
{
case "Dell": nb = new Dell();
break;
case "IBM": nb = new IBM();
break;
case "Acer": nb = new Acer();
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 IBM : NoteBook
{
public override void SayHello()
{
Console.WriteLine("我是IBM笔记本");
}
}
public class Dell : NoteBook
{
public override void SayHello()
{
Console.WriteLine("我是戴尔笔记本");
}
}
}