コード例 #1
0
        //static void Main(string[] args)
        //{
        //    LeiFeng studentA = SimpleFactory.CreateLeiFeng("学雷锋的大学生");
        //    studentA.BuyRice();
        //    LeiFeng studentB = SimpleFactory.CreateLeiFeng("学雷锋的大学生");
        //    studentA.Sweep();
        //    LeiFeng studentC = SimpleFactory.CreateLeiFeng("学雷锋的大学生");
        //    studentA.Wash();

        //    Console.Read();
        //}
        #endregion


        #region 工厂方法学雷锋实现
        static void Main(string[] args)
        {
            IFactory factory = new UndergraduateFactory();
            LeiFeng  student = factory.CreateLeiFeng();

            student.BuyRice();
            student.Sweep();
            student.Wash();
            Console.Read();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            //创建工厂对象
            UndergraduateFactory uFactory = new UndergraduateFactory();
            VolunteerFactory     vFactory = new VolunteerFactory();

            //工厂返回雷锋(父类) 实际上是子类
            LeiFeng undergraduate = uFactory.CreateLeiFeng();
            LeiFeng volunteer     = vFactory.CreateLeiFeng();

            undergraduate.Sweep();
            volunteer.BuyRice();

            Console.ReadKey();
        }
コード例 #3
0
        public static LeiFeng CreateLeiFeng(string type)
        {
            LeiFeng result = null;

            switch (type)
            {
            case "学雷锋的大学生":
                result = new Undergraduate();
                break;

            case "社区志愿者":
                result = new Volunteer();
                break;
            }

            return(result);
        }
コード例 #4
0
 static void Main(string[] args)
 {
     IFactory factory = new UndergraduateFactory();
     LeiFeng  student = factory.CreateLeiFeng();
 }