コード例 #1
0
        static void Main(string[] args)
        {
            //NewMethod();
            //NewMethod1();
            //NewMethod2();
            IFactory factory  = new UndergraduateFactory();
            IFactory factory2 = new VolunteerFactory();
            LeiFeng  stu      = factory.CreateLeiFeng();
            LeiFeng  vol      = factory2.CreateLeiFeng();

            stu.Sweep();
            vol.BuyRice();
            Console.ReadLine();
        }
コード例 #2
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
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Console.ReadKey();
            UndergraduateFactory factory = new UndergraduateFactory();
            Leifeng student = factory.CreateLeiFeng();

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

            Console.WriteLine("\n --------------------------");
            Console.ReadKey();

            IFactory factory2  = new VolunteerFactory();
            Leifeng  volunteer = factory2.CreateLeiFeng();

            volunteer.Sweep();
            volunteer.Wash();
            volunteer.BuyRice();

            Console.ReadKey();
        }