예제 #1
0
파일: Program.cs 프로젝트: gzx941016/-.net-
        static void Main(string[] args)
        {
            //设计这个项目的一种方式,一共有23种设计模式
            //简单工厂的核心:根据用户的输入创建对象赋值给父类

            Console.WriteLine("请输入想要生产的品牌");
            string   brand = Console.ReadLine();
            NoteBook nb    = GetNoteBook(brand);

            nb.SayHello();
            Console.ReadKey();
        }
예제 #2
0
파일: Program.cs 프로젝트: gzx941016/-.net-
        public static NoteBook GetNoteBook(string brand)
        {
            NoteBook nb = null;

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

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

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