예제 #1
0
        static void Main(string[] args)
        {
            //
            //基本方式:薛磊风代表大学生学习雷锋
            LeiFeng xueleifeng = new Undergraduate();

            xueleifeng.BuyRice();
            xueleifeng.Sweep();
            xueleifeng.Wash();

            LeiFeng student1 = new Undergraduate();
            student1.BuyRice();
            LeiFeng student2 = new Undergraduate();
            student2.Sweep();
            LeiFeng student3 = new Undergraduate();
            student3.Wash();

            //简单工厂模式
            LeiFeng studentA = SimpleFactory.CreateLeiFeng("学雷锋的大学生");
            studentA.BuyRice();
            LeiFeng studentB = SimpleFactory.CreateLeiFeng("学雷锋的大学生");
            studentB.Sweep();
            LeiFeng studentC = SimpleFactory.CreateLeiFeng("学雷锋的大学生");
            studentC.Wash();

            //工厂方法模式
            IFactory factory = new UndergraduateFactory();
            LeiFeng student = factory.CreateLeiFeng();

            student.BuyRice();
            student.Sweep();
            student.Wash();

            Console.Read();
        }
        private static void NewMethod1()
        {
            LeiFeng learnFromLeiFeng = new Undergraduate();

            learnFromLeiFeng.BuyRice();
            learnFromLeiFeng.Sweep();
            learnFromLeiFeng.Wash();
            Console.Read();
        }
예제 #3
0
        static void Main(string[] args)
        {
            #region 计算器部分
            IFactory  operFactory = new AddFactory();
            Operation oper        = operFactory.CreateOperation();
            oper.NumberA = 1;
            oper.NumberB = 2;
            double result = oper.GetResult();

            Console.WriteLine(result);
            #endregion

            #region 基本方式:薛磊风代表大学生学习雷锋
            LeiFeng xueleifeng = new Undergraduate();

            xueleifeng.BuyRice();
            xueleifeng.Sweep();
            xueleifeng.Wash();

            LeiFeng student1 = new Undergraduate();
            student1.BuyRice();
            LeiFeng student2 = new Undergraduate();
            student2.Sweep();
            LeiFeng student3 = new Undergraduate();
            student3.Wash();
            #endregion

            #region 简单工厂模式
            LeiFeng studentA = SimpleFactory.CreateLeiFeng("学雷锋的大学生");
            studentA.BuyRice();
            LeiFeng studentB = SimpleFactory.CreateLeiFeng("学雷锋的大学生");
            studentB.Sweep();
            LeiFeng studentC = SimpleFactory.CreateLeiFeng("学雷锋的大学生");
            studentC.Wash();
            #endregion

            #region 工厂方法模式
            ILeiFengFactory factory = new UndergraduateFactory();
            LeiFeng         student = factory.CreateLeiFeng();

            student.BuyRice();
            student.Sweep();
            student.Wash();

            Console.Read();
            #endregion
        }
예제 #4
0
        static void Main(string[] args)
        {
            //
            //基本方式:胡鞏代表大學生學習南丁格爾
            Nightingale hugong = new Undergraduate();

            hugong.BuyRice();
            hugong.Sweep();
            hugong.Wash();


            Nightingale student1 = new Undergraduate();

            student1.BuyRice();
            Nightingale student2 = new Undergraduate();

            student2.Sweep();
            Nightingale student3 = new Undergraduate();

            student3.Wash();



            //簡單工廠模式
            Nightingale studentA = SimpleFactory.CreateNightingale("學南丁格爾的大學生");

            studentA.BuyRice();
            Nightingale studentB = SimpleFactory.CreateNightingale("學南丁格爾的大學生");

            studentB.Sweep();
            Nightingale studentC = SimpleFactory.CreateNightingale("學南丁格爾的大學生");

            studentC.Wash();


            //工廠方法模式
            IFactory    factory = new UndergraduateFactory();
            Nightingale student = factory.CreateNightingale();

            student.BuyRice();
            student.Sweep();
            student.Wash();

            Console.Read();
        }
예제 #5
0
        static void Main(string[] args)
        {
            //
            //基本方式:薛磊风代表大学生学习雷锋
            LeiFeng xueleifeng = new Undergraduate();

            xueleifeng.BuyRice();
            xueleifeng.Sweep();
            xueleifeng.Wash();


            LeiFeng student1 = new Undergraduate();

            student1.BuyRice();
            LeiFeng student2 = new Undergraduate();

            student2.Sweep();
            LeiFeng student3 = new Undergraduate();

            student3.Wash();



            //简单工厂模式
            LeiFeng studentA = SimpleFactory.CreateLeiFeng("学雷锋的大学生");

            studentA.BuyRice();
            LeiFeng studentB = SimpleFactory.CreateLeiFeng("学雷锋的大学生");

            studentB.Sweep();
            LeiFeng studentC = SimpleFactory.CreateLeiFeng("学雷锋的大学生");

            studentC.Wash();


            //工厂方法模式
            IFactory factory = new UndergraduateFactory();
            LeiFeng  student = factory.CreateLeiFeng();

            student.BuyRice();
            student.Sweep();
            student.Wash();

            Console.Read();
        }