예제 #1
0
        static void Main(string[] args)
        {
            SoldierFactory factory = new SoldierFactory();
            AK47           ak47    = new AK47();

            for (int i = 0; i < 100; i++)
            {
                Soldier soldier = null;
                if (i <= 20)
                {
                    soldier = factory.GetSoldier("士兵" + (i + 1), ak47, SoldierType.Normal);
                }
                else
                {
                    soldier = factory.GetSoldier("士兵" + (i + 1), ak47, SoldierType.Water);
                }
                soldier.Fight();
            }
            Console.Read();
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Console.WriteLine("--------------------FlyweightPattern--------------------");
            Console.WriteLine();
            var factory = new SoldierFactory();
            var ak47    = new AK47();

            for (int i = 0; i < 10000; i++)
            {
                Soldier soldier = null;
                if (i < 5000)
                {
                    soldier = factory.GetSoldier($"士兵A", ak47, SoldierType.Normal);
                }
                else
                {
                    soldier = factory.GetSoldier($"士兵B", ak47, SoldierType.Water);
                }
                soldier.Fight();
            }
            Console.WriteLine("complete!");
            Console.ReadKey();
        }