Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
 public ConcreteIterator(ConcreteAggregate aggregate)
 {
     this.aggregate = aggregate;
 }
Ejemplo n.º 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();
        }
Ejemplo n.º 4
0
 public ConcreteIteratorDesc(ConcreteAggregate aggregate)
 {
     this.aggregate = aggregate;
     current = aggregate.Count - 1;
 }
Ejemplo n.º 5
0
 public ConcreteIterator(ConcreteAggregate aggregate)
 {
     this.aggregate = aggregate;
 }