Beispiel #1
0
        static void Main(string[] args)
        {
            ConcreteAggregate a = new ConcreteAggregate();
            a[0] = "Item A";
            a[1] = "Item B";
            a[2] = "Item C";
            a[3] = "Item D";

            //ConcreteIterator i = new ConcreteIterator(a);
            Iterator i = a.CreateIterator();
            Console.WriteLine("Iterating over collection:");
            object item = i.First();
            while (item != null)
            {
                Console.WriteLine(item);
                item = i.Next();
            }
            // Wait for user
            Console.Read();
        }
Beispiel #2
0
 public ConcreteIterator(ConcreteAggregate aggregate)
 {
     this.aggregate = aggregate;
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            ConcreteAggregate a = new ConcreteAggregate();

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

            Iterator i = new ConcreteIterator(a);
            //Iterator i = new ConcreteIteratorDesc(a);
            object item = i.First();
            while (!i.IsDone())
            {
                Console.WriteLine("{0} 请买车票!", i.CurrentItem());
                i.Next();
            }

            Console.Read();
        }
Beispiel #4
0
 public ConcreteIteratorDesc(ConcreteAggregate aggregate)
 {
     this.aggregate = aggregate;
     current = aggregate.Count - 1;
 }
Beispiel #5
0
 public ConcreteIterator(ConcreteAggregate aggregate)
 {
     this.aggregate = aggregate;
 }