1 / 14

Iterator and Composite Design Patterns

Iterator and Composite Design Patterns. Tuc Goodwin. Agenda. Scenario Iterator Pattern Iterator Participants Composite Pattern Composite Pattern Participants. The Book we are Using. Why use an Iterator Pattern?.

Download Presentation

Iterator and Composite Design Patterns

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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

  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?

  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

More Related