示例#1
0
        static void Main(string[] args)
        {
            //使用多态中的抽象类实现简单工厂模式
            Console.WriteLine("请输入需要的电脑品牌");
            string   brand = Console.ReadLine();
            NoteBook nb    = getNoteBook(brand);

            nb.Say();
        }
示例#2
0
        public static NoteBook getNoteBook(string brand)
        {
            NoteBook nb = null;

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

            case "lenovo":
                nb = new Lenovo();
                break;
            }

            return(nb);
        }