Presentation is loading. Please wait.

Presentation is loading. Please wait.

Iterator and Composite Design Patterns

Similar presentations


Presentation on theme: "Iterator and Composite Design Patterns"— Presentation transcript:

1 Iterator and Composite Design Patterns
Tuc Goodwin

2 Agenda Scenario Iterator Pattern Iterator Participants
Composite Pattern Composite Pattern Participants

3 The Book we are Using Head First Design Patterns (ISBN: )

4 Why use an Iterator Pattern?
The Iterator pattern allows you to move through a list or collection of data using a standard interface without having to know the details of the internal representation of the data.

5 Iterator Pattern definition
Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation

6 Iterator Participants
The classes and/or objects participating in this pattern are: Iterator  (AbstractIterator) defines an interface for accessing and traversing elements. ConcreteIterator  (Iterator) implements the Iterator interface. keeps track of the current position in the traversal of the aggregate. Aggregate  (AbstractCollection) defines an interface for creating an Iterator object ConcreteAggregate  (Collection) implements the Iterator creation interface to return an instance of the proper ConcreteIterator

7 Lou’s Diner & Mel’s Diner
Lou implemented his menus as an ArrayList Mel implemented his menus as an Array We need to combine the two and display all of the menu items. Do we really want to implement this loop twice? Once for an ArrayList and once for an Array?

8 DEMO BEFORE PATTERNS / Interfaces

9 Here’s where we are going…

10 Demo II After Patterns / Interfaces

11 Composite Design definition
Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.

12 Composite Participants
The classes and/or objects participating in this pattern are: Component   (DrawingElement) declares the interface for objects in the composition. implements default behavior for the interface common to all classes, as appropriate. declares an interface for accessing and managing its child components. (optional) defines an interface for accessing a component's parent in the recursive structure, and implements it if that's appropriate. Leaf   (PrimitiveElement) represents leaf objects in the composition. A leaf has no children. defines behavior for primitive objects in the composition. Composite   (CompositeElement) defines behavior for components having children. stores child components. implements child-related operations in the Component interface. Client  (CompositeApp) manipulates objects in the composition through the Component interface.

13 Questions? 9/17/2018

14 Next Time .NET Development
January 10 Beginning ASP.NET: DataGrids and Gridviews February 14 Beginning ASP.NET – Part 3 March 14 Beginning ASP.NET – Part 4 April 11 LINQ Patterns January 10 State Pattern February 14 Proxy Pattern March 14 Compound Patterns April 11 Better Living with Patterns


Download ppt "Iterator and Composite Design Patterns"

Similar presentations


Ads by Google