Jim Fawcett CSE776 – Design Patterns Summer 2003

Slides:



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

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)
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.
1 Dept. of Computer Science & Engineering, York University, Toronto Software Development CSE3311 Composite Pattern.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
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.
Design Patterns.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
© Spiros Mancoridis 27/09/ Software Design Topics in Object-Oriented Design Patterns Material drawn from [Gamma95] and [Coplien95] Revised and augmented.
BTS530: Major Project Planning and Design The Composite Pattern All References and Material From: Design Patterns,by (GOF!) E.Gamma, R.Helm, R.Johnson,
CSE 403 Lecture 14 Design Patterns. Today’s educational objective Understand the basics of design patterns Be able to distinguish them from design approaches.
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.
CS 210 Final Review November 28, CS 210 Adapter Pattern.
Introduction (Continued) Design Patterns (I) Lecture Two.
The Visitor Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The Interpreter Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
1 Advanced Object-oriented Design – Principles and Patterns Structural Design Patterns.
The Facade Pattern (Structural) ©SoftMoore ConsultingSlide 1.
Example to motivate discussion We have two lists (of menu items) one implemented using ArrayList and another using Arrays. How does one work with these.
Reference – Object Oriented Software Development Using Java - Jia COP 3331 Object Oriented Analysis and Design Chapter 10 – Patterns Jean Muhammad.
S.Ducasse Stéphane Ducasse 1 Adapter.
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.
Command Pattern. Intent encapsulate a request as an object  can parameterize clients with different requests, queue or log requests, support undoable.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Composite Pattern Himanshu Gupta Shashank Hegde CSE776 – Design Patterns Fall 2011 Good composition is like a suspension bridge - each line adds strength.
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Presented by FACADE PATTERN
Mediator Design Pattern
Abstract Factory Pattern
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University
Factory Patterns 1.
Intent To provide a framework to manage the process of software salvage and promote loose coupling through message passing. Salvage means recycling significant.
Composite Design Pattern
Flyweight Design Pattern
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)
Binary Tree and General Tree
Object-Oriented Design
Presentation by Julie Betlach 7/02/2009
More Design Patterns 1.
Design Patterns - A few examples
More Design Patterns 1.
Design Patterns A Case Study: Designing a Document Editor
Object Oriented Design Patterns - Structural Patterns
Behavioral Patterns Part-I introduction UNIT-VI
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Structural Pattern part-I introduction
Strategy Design Pattern
Lesson 5: More on Creational Patterns
Composite Design Pattern By Aravind Reddy Patlola.
Adapter Pattern Jim Fawcett
Software Design Lecture : 36.
Iterator Design Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014
Adapter Pattern Jim Fawcett
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Presentation transcript:

Jim Fawcett CSE776 – Design Patterns Summer 2003 Composite Pattern Jim Fawcett CSE776 – Design Patterns Summer 2003

Intent Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects in a uniform way.

Motivation – Dynamic Structure

Motivation – Static Structure

Applicability Use the Composite pattern when: You need to represent part-whole hierarchies of objects You want clients to ignore the differences between parts and wholes (individual objects and compositions of objects) The compositions are created dynamically – at run time – so use composite: when you need to build a complex system from primitive components and previously defined subsystems. This is especially important when the construction process will reuse subsystems defined earlier.

Structure – Plan A

Participants – Plan A Component (Graphic) Client declares 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 Client manipulates objects in the composition through the Component interface

Participants – Plan A Leaf Composite (picture) Represents leaf objects in the composition. A leaf has no children. Defines behavior for primitive objects in the composition. Composite (picture) Defines behavior for components having children. Stores child components. Implements child-related operations in the Component interface.

Structure – Plan B

Participants – Plan B Component (Graphic) Client declares interface for objects in the composition Client manipulates objects in the composition through the Composite interface

Participants – Plan B Leaf Composite (picture) Represents leaf objects in the composition. A leaf has no children. Defines behavior for primitive objects in the composition. Composite (picture) Defines behavior for components having children. declares an interface for accessing and managing its child components Stores child components. Implements child-related operations in the Component interface.

Collaborators Plan A: Clients use the Component class interface to interact with objects in the composite structure. Plan B: Clients use the Composite class interface to interact with objects in the composite structure. If the recipient is a Leaf then the request is handled directly. If the recipient is a composite, then it usually forwards request to its child components.

Tree Structure

Consequences The Composite pattern: Defines class hierarchies consisting of primitives and composites When a client expects a primitive it can also take a composite. Makes it easier to add new components. Newly defined primitives or composites will work automatically with existing structures and client code. Can make your design too general. Since its easy to add new components it is hard to restrict the components of a composite. Composite doesn’t support using the type system to support these constraints for you, since all components have the same base type.

Know Uses Authors cite many windowing toolkits. The FORTH language defines its statements using an extensible dictionary which implements the Composite pattern.

Related Patterns Decorator – very similar structure and intent Iterator can be used to traverse Composites.