示例#1
0
文件: Program.cs 项目: cocos56/CS
        static void Main(string[] args)
        {
            Console.WriteLine("请你输入您想要的笔记本品牌");
            string   brand = Console.ReadLine();
            NoteBook nb    = GetNoteBook(brand);

            nb.SayHello();
            Console.ReadKey();
        }
示例#2
0
文件: Program.cs 项目: cocos56/CS
        /// <summary>
        /// 简单工厂设计模式的核心:根据用户的输入创建对象 赋值给父类
        /// </summary>
        /// <param name="brand"></param>
        /// <returns></returns>
        public static NoteBook GetNoteBook(string brand)
        {
            NoteBook nb = null;

            switch (brand)
            {
            case "Lenovo": nb = new Lenovo();
                break;

            case "IBM": nb = new IBM();
                break;

            case "Acer": nb = new Acer();
                break;

            case "Dell": nb = new Dell();
                break;
            }
            return(nb);
        }