Composite Pattern Himanshu Gupta Shashank Hegde CSE776 – Design Patterns Fall 2011 Good composition is like a suspension bridge - each line adds strength.

Slides:



Advertisements
Similar presentations
1 Structural Design Patterns - Neeraj Ray. 2 Structural Patterns - Overview n Adapter n Bridge n Composite n Decorator.
Advertisements

Design Patterns Design Patterns Composite Pattern Observer Pattern.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Composite Design Pattern (1) –A structural design pattern.
March Ron McFadyen1 Composite Used to compose objects into tree structures to represent part-whole hierarchies Composite lets clients treat.
Fall 2009ACS-3913 Ron McFadyen Composite Pattern Problem: How do we treat a composition structure of objects the same way as a non-composite object? Arises.
The Composite Pattern. Owners (No Twins, Expos) Managers (No Twins, Expos) Congress (No Twins, Expos) Media (No Twins, Expos) Radio (No Twins, Expos)
Design Pattern Course Builder Pattern 1 Mahdieh Monzavi AmirKabir University of Technology, Department of Computer Engineering & Information Technology.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0More on Structural Patterns - Page L7-1 PS95&96-MEF-L14-1 Dr. M.E. Fayad Creationa.
Software Design and Documentation Individual Presentation: Composite Pattern 9/11/03.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VI Composite, Iterator, and Visitor Patterns.
OOMPA Lecture 9 Design Patterns Composite Pattern Observer Pattern.
1 Dept. of Computer Science & Engineering, York University, Toronto Software Development CSE3311 Composite Pattern.
1 PH Chapter 1 (pp. 1-10) GoF Composite Pattern (pp ) PH Ch 2 through Fundamentals (pp ) Presentation by Julie Betlach 5/28/2009.
Composite Design Pattern. Motivation – Dynamic Structure.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Composit Pattern.
ADAPTER PATTERN BY Sravanthi Karumanchi. Structure Pattern Structure patterns are concerned with how classes and objects are composed to form large structures.
SE2811 Week 7, Class 1 Composite Pattern Applications Conceptual form Class structure Coding Example Lab Thursday: Quiz SE-2811 Slide design: Dr. Mark.
BTS530: Major Project Planning and Design The Composite Pattern All References and Material From: Design Patterns,by (GOF!) E.Gamma, R.Helm, R.Johnson,
SDP Structural Pattern. SDP-2 Structural Patterns Concerned with how classes and objects are composed to form large structures Class Patterns use.
Structural Design Patterns
08 - StructuralCSC4071 Structural Patterns concerned with how classes and objects are composed to form larger structures –Adapter interface converter Bridge.
Structural Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Strategy Pattern.
Composite Pattern ( ) Pattern Hatching Chpt 1-2 Presentation by Joe Barzilai 1/30/2006.
Billy Bennett June 22,  Intent Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.
COMPOSITE. Design Pattern Space Purpose ScopeCreationalStructuralBehavioral ClassFactory MethodAdapterInterpreter Template Method ObjectAbstract factory.
The Facade Pattern (Structural) ©SoftMoore ConsultingSlide 1.
Reference – Object Oriented Software Development Using Java - Jia COP 3331 Object Oriented Analysis and Design Chapter 10 – Patterns Jean Muhammad.
CSE 332: Design Patterns (Part II) Last Time: Part I, Familiar Design Patterns We’ve looked at patterns related to course material –Singleton: share a.
Design Patterns. Outline Purpose Purpose Useful Definitions Useful Definitions Pattern Overview Pattern Overview.
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
COMPOSITE PATTERN NOTES. The Composite pattern l Intent Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Abstract Factory Pattern
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Slide design: Dr. Mark L. Hornick
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University
Factory Patterns 1.
Software Design and Architecture
Composite Design Pattern
Composite Pattern SE2811 Software Component Design
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Abstract Factory Pattern
Iterator and Composite Design Patterns
Decorator Design Pattern
Intent (Thanks to Jim Fawcett for the slides)
More Design Patterns 1.
Composite Pattern Oct 7, 2003 A composite is a group of objects in which some objects contain others; one object may represent groups, and another.
Chapter 8, Object Design Introduction to Design Patterns
Design Patterns Satya Puvvada Satya Puvvada.
Design Patterns - A few examples
More Design Patterns 1.
Design Patterns A Case Study: Designing a Document Editor
Jim Fawcett CSE776 – Design Patterns Summer 2003
Software Development CSE3311
Composite Pattern Context:
PH Chapter 3 Thanks for the Memory Leaks Pushme-Pullyu (pp
Structural Patterns: Adapter and Bridge
13. Composite Pattern SE2811 Software Component Design
Software Design Lecture : 35.
Informatics 122 Software Design II
13. Composite Pattern SE2811 Software Component Design
Composite Design Pattern By Aravind Reddy Patlola.
Adapter Pattern Jim Fawcett
Software Design Lecture : 36.
Software Design Lecture 10.
Adapter Pattern Jim Fawcett
Presentation transcript:

Composite Pattern Himanshu Gupta Shashank Hegde CSE776 – Design Patterns Fall 2011 Good composition is like a suspension bridge - each line adds strength and takes none away. Robert Henri Robert Henri

Intent A Structural Pattern: Concerned with how classes and objects are combined to create larger structures Compose Objects into tree structures to represent part-whole hierarchies. It lets clients treat individual objects and compositions of objects uniformly.

Motivation Can make complex diagrams out of simple components. Easy to deal with tree structured data.

Structure

Participants The classes and objects participating in this pattern are: ◦ Component ◦ Leaf ◦ Composite ◦ Client

Collaborations Client use Component class to interact with objects in composite structure. If recipient is a leaf, then request is handled directly. If the recipient is a composite then it usually forwards request to child component. It may perform additional activities before and after forwarding.

Applicability Can represent part-whole hierarchies of Objects. Supports client ignorance of the difference between composition of objects and individual objects.

Consequences Class hierarchies consists of primitive and composite objects. Clients should treat the composite and leaf uniformly. Makes it easier to add new kind of composite or leaf subclasses. Disadvantage of making design overly general. Harder to restrict the components of a composite.

Implementation Reference from child components to their parents can simplify the traversal and management of a composite structure. Useful to share component. Problem when component can have no more than 1 parent. Composite pattern goal-to make client unaware whether its leaf or composite. As many common operations for composite and leaf. Should components implement a list of Components. Caching to improve performance Who should delete components. –Composite ? Best Data structure for storing components ??

Safety Vs Transparency Usually Composite defines add and remove operation for managing children – what if components does..? Defining child management interface at the root of class hierarchy gives you transparency.It costs you safety. Defining child management interface in composite gives you safety. You lose out on transparency. Solution…??

Sample Code-component #include class component { public: component(void); virtual bool Add(component* addent); virtual bool Remove(component* removed); virtual component* GetChild(int); virtual void operation(); ~component(void); };

Sample Code-Composition #ifndef COMPOSITE_H #include "component.h" #include class Composite :public component { public: Composite(void); ~Composite(void); virtual bool Add(component*); virtual bool Remove(component*); component* GetChild(int); virtual void operation(); private: std::vector children; }; #endif

Sample Code- Leaf #ifndef LEAF_H #include "component.h" #include using namespace std; class Leaf :public component { public: Leaf(void); ~Leaf(void); void virtual operation(); }; #endif

Uses Google Maps PaintBrush. Our example and its extensibility.

Questions???