Esempio n. 1
0
        public override IMorningLight GetMorningLight(string type)
        {
            IMorningLight brand = null;

            switch (type)
            {
            case "NoteBook":
                brand = new NoteBook();
                break;

            case "Pen":
                brand = new Pen();
                break;

            default:
                break;
            }
            return(brand);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("抽象工厂模式");
            // 获取小米品牌工厂
            AbstractFactory mi_Factory = FactoryProducter.GetFactory("MIBrand");

            // 获取小米品牌下得小米手机商品
            IMIBrand mi_Phone = mi_Factory.GetMIBrand("Phone");

            // 调用方法
            mi_Phone.PrintName();

            // 获取晨光品牌工厂
            AbstractFactory morning_Factory = FactoryProducter.GetFactory("MorningLight");

            // 获取晨光品牌下得笔记本商品
            IMorningLight morning_Phone = morning_Factory.GetMorningLight("NoteBook");

            // 调用方法
            morning_Phone.PrintIn();

            Console.ReadLine();
        }