Пример #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("欢迎大家来到软谋教育.net高级班公开课程");


            Human human2 = new Human();

            human2.ShowKing();
            //IRace human1 = new Human();

            IFactoryMethod humanFactory = new HumanFactory();
            IRace          human        = humanFactory.CreateInstance();

            human.ShowKing();


            //Five five = new Five();

            IFactoryMethod fiveFactory = new FiveFactory();
            IRace          five        = fiveFactory.CreateInstance();

            five.ShowKing();


            Console.Read();
        }
Пример #2
0
        static void Main(string[] args)
        {
            try
            {
                {
                    Human human = new Human();//1 到处都是细节
                }
                {
                    IRace human = new Human();//2 左边是抽象  右边是细节
                }
                {
                    //human.
                    IFactory factory = new HumanFactory();//包一层
                    IRace    race    = factory.CreateRace();
                }
                {
                    //Undead
                    IFactory factory = new UndeadFactory();
                    IRace    race    = factory.CreateRace();
                }
                {
                    IRace five = new Five();//修改
                }

                {
                    //five
                    IFactory factory = new FiveFactory();
                    IRace    race    = factory.CreateRace();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.Read();
        }