类的工厂加工模式

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笔记本");
        }
    }
}
转载请注明出处:  https://www.cntworld.cn
智能工控 » 类的工厂加工模式

发表回复

提供最优质的资源集合

立即查看 了解详情