Example #1
0
        static void Main(string[] args)
        {
            Vegetable vge = new RootVegetable();

            vge.PlantVegetable();
            Console.ReadLine();

            Vegetable vge1 = (Vegetable)SimpleVegetableFactory.GetVegetableInstance("茎菜类蔬菜");

            vge1.PlantVegetable();
            Vegetable vge2 = (Vegetable)SimpleVegetableFactory.GetVegetableInstance("根菜类蔬菜");

            vge2.PlantVegetable();
            Console.ReadLine();


            // 初始化工厂
            VegetableFactory Factory = new RootVegetableFactory();
            //种植根菜类蔬菜
            Vegetable vge3 = Factory.GetVegetableInstance();

            vge3.PlantVegetable();
            Console.ReadLine();


            string           factoryName = ConfigurationManager.AppSettings["factoryName"];
            VegetableFactory vf          = (VegetableFactory)Assembly.Load("Factory_Siample").CreateInstance(factoryName);
            Vegetable        vge4        = vf.GetVegetableInstance();

            vge4.PlantVegetable();
            Console.ReadLine();
        }
Example #2
0
        public static Vegetable GetVegetableInstance(string vegetable)
        {
            Vegetable vge = null;

            if (vegetable.Equals("根菜类蔬菜"))
            {
                vge = new RootVegetable();
            }
            else if (vegetable.Equals("茎菜类蔬菜"))
            {
                vge = new StemVegetable();
            }

            return(vge);
        }