Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            var aggregate = new ConcreteAggregate
            {
                [0] = "大鸟",
                [1] = "小菜",
                [2] = "行李",
                [3] = "老外",
                [4] = "公交员工",
                [5] = "小偷"
            };

            Console.WriteLine("ConcreteIterator:");
            Iterator iterator = new ConcreteIterator(aggregate);

            do
            {
                Console.WriteLine($"{iterator.CurrentItem()} 请买车票");
                iterator.Next();
            } while (!iterator.IsDone());

            Console.WriteLine("ConcreteIteratorDesc:");
            Iterator iteratorDesc = new ConcreteIteratorDesc(aggregate);

            do
            {
                Console.WriteLine($"{iteratorDesc.CurrentItem()} 请买车票");
                iteratorDesc.Next();
            } while (!iteratorDesc.IsDone());

            Console.ReadLine();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            ConcreteAggregate passengers = new ConcreteAggregate();

            passengers[0] = "大鸟";
            passengers[1] = "小菜";
            passengers[2] = "行李";
            passengers[3] = "老外";
            passengers[4] = "公司内部员工";
            passengers[5] = "小偷";

            Iterator iPassenger = new ConcreteIterator(passengers);

            //object item = iPassenger.First();
            while (!iPassenger.IsDone())
            {
                Console.WriteLine("{0}请买票", iPassenger.CuurentItem());
                iPassenger.Next();
            }

            Iterator iPassengerDesc = new ConcreteIteratorDesc(passengers);

            while (!iPassengerDesc.IsDone())
            {
                Console.WriteLine("{0}请买票", iPassengerDesc.CuurentItem());
                iPassengerDesc.Next();
            }
        }
Exemplo n.º 3
0
        public void TestCase1()
        {
            var aggregate = new ConcreteAggregate();

            aggregate[0] = "Apple";
            aggregate[1] = "Orange";
            aggregate[2] = "Strawberry";

            var iterator = new ConcreteIterator(aggregate);

            object item = iterator.First();

            while (iterator.IsDone() == false)
            {
                Console.WriteLine(item);
                item = iterator.Next();
            }
        }