Example #1
0
        /// <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;

            case "SAMSUNG":
                nb = new SAMSUNG();
                break;
            }
            return(nb);
        }
Example #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("请输入你想要的品牌电脑:");
            string brand = Console.ReadLine();

            NoteBook nb = GetNoteBook(brand);

            nb.SayHello();
            Console.ReadKey();
        }