private DuckFlock CreateTestFlock() { DuckFlock flock = new DuckFlock(); flock.Add(new MallardDuck { Name = "Fred the Mallard" }); flock.Add(new MandarinDuck { Name = "Aaron the Mandarin" }); return flock; }
// Iterator pattern with aggregate void iterateMyDucks_Click(object sender, EventArgs e) { DuckFlock flock = new DuckFlock(); flock.Add(new MallardDuck()); flock.Add(new MandarinDuck()); flock.Add(new RubberDuck()); LoopThroughDucksUsingIterator(flock); }
private void LoopThroughDucksUsingIterator(DuckFlock flock) { IIterator<IQuackable> duckIterator = new DuckIterator(flock); IQuackable currentDuck = duckIterator.Current(); while (currentDuck != null) { currentDuck.Quack(); currentDuck = duckIterator.Next(); } }
public NameSorter(DuckFlock flockToSort) { this.flockToSort = flockToSort; }