Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Composite Design Pattern (1) –A structural design pattern.

Slides:



Advertisements
Similar presentations
March Ron McFadyen1 Composite Used to compose objects into tree structures to represent part-whole hierarchies Composite lets clients treat.
Advertisements

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 McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 10 Using arrays to create collections.
INTERPRETER Main Topics What is an Interpreter. Why should we learn about them.
UML – Class Diagrams.
Insertion Sort.
Iterator Matt G. Ellis. Intent Metsker: Provide a way to access elements of a collection sequentially. GoF: Provide a way to access the elements of an.
Iterators T.J. Niglio Computer & Systems Engineering Fall 2003 Software Design & Documentation Object Behavioral.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
Patterns – Day 10 Composite Responsibility Reminder: Faculty candidate talk Today 4:20 PM O-267. Salman Azhar: Optimal Prediction via Data Compression.
Visitor Matt G. Ellis. Intent Metsker: Let developers define a new operation for a hierarchy without changing the hierarchy classes. GoF: Represent an.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 10 *Arrays with more than one dimension *Java Collections API.
Software Design and Documentation Individual Presentation: Composite Pattern 9/11/03.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Design Patterns.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Copyright © The McGraw-Hill Companies, Inc
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Abstract Superclasses and Abstract Methods When.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 13 Polymorphism is-a relationships Interfaces.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 10 Using arrays to create collections.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VI Composite, Iterator, and Visitor Patterns.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Proxy Design Pattern (1) –A structural design pattern.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 2 Image Slides.
The Unified Modeling Language (UML) Class Diagrams.
Chapter 8 Traffic-Analysis Techniques. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 8-1.
1 Dept. of Computer Science & Engineering, York University, Toronto Software Development CSE3311 Composite Pattern.
Behavioral Patterns C h a p t e r 5 – P a g e 128 BehavioralPatterns Design patterns that identify and realize common interactions between objects Chain.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Façade Design Pattern (1) –A structural design pattern.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Factory Method Design Pattern (1) –A creational design.
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.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. C H A P T E R S E V E N Object-Oriented Programming.
Design Patterns in Java Chapter 5 Composite Summary prepared by Kirk Scott 1.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
Unit 25 Composite Summary prepared by Kirk Scott 1.
17.16 Synthesis of Thyroid Hormone (TH) Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Slide number: 1.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
Object Oriented Software Engineering Chapter 16 and 17 review 2014/06/03.
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.
The Visitor Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. C H A P T E R T W O Syntax.
COMPOSITE. Design Pattern Space Purpose ScopeCreationalStructuralBehavioral ClassFactory MethodAdapterInterpreter Template Method ObjectAbstract factory.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. C H A P T E R F I V E Memory Management.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 18 List ADT Animated Version.
Copyright ©2004 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4-1 Probability and Counting Rules CHAPTER 4.
Copyright © 2012 Pearson Education, Inc. Chapter 10 Advanced Topics.
COMPOSITE PATTERN NOTES. The Composite pattern l Intent Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients.
Chapter 13 Transportation Demand Analysis. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4-1 CHAPTER 4 Counting Techniques.
1 Java Review Outline Java Primitives, Program Structure Operators, Control Flow, Loops Classes and Objects Arrays and ArrayList Most of these slides are.
Composite Pattern Himanshu Gupta Shashank Hegde CSE776 – Design Patterns Fall 2011 Good composition is like a suspension bridge - each line adds strength.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Design Patterns – Group 2 Iterator, Proxy, Adapter, Decorator.
Composite Design Pattern
Composite Pattern SE2811 Software Component Design
Iterator and Composite Design Patterns
Summary prepared by Kirk Scott
Jim Fawcett CSE776 – Design Patterns Summer 2003
Software Development CSE3311
Behavioral Patterns Part-I introduction UNIT-VI
13. Composite Pattern SE2811 Software Component Design
Software Design Lecture : 35.
13. Composite Pattern SE2811 Software Component Design
Software Design Lecture : 36.
Iterator Design Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014
Presentation transcript:

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Composite Design Pattern (1) –A structural design pattern Decouples interface from implementation –Intent To structure composites into a tree structure; to let clients deal with individual objects and compositions of objects uniformly

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Composite Design Pattern (2) –Problem Situation I: Wish to represent recursive data Situation II: Wish to isolate client from worrying about whether the data is a terminal case or a recursive case

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Composite Design Pattern (3) –Non-software example Arithmetic Expressions –Operations can be applied to terminals and composites alike

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Composite Design Pattern (4) –Abstract Description Object Design Pattern Key relationships

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Composite Design Pattern (5) –Abstract Description Sequence Diagram

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1-6 The Composite Design Pattern (6) getMachineCount() returns the number of machines in any given component (Machine returns 1; MachineComposite returns sum of the counts for each component) MachineComponent getMachineCount() components: List getMachineCount() MachineComposite Machine getMachineCount()

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Composite Design Pattern (7) –Consequences Recursive data structures lends itself to recursive processing Simplifies the client –No concern for looping on composites Explicit hierarchy makes it easier to add new leaf of composite types

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Composite Design Pattern (8) –Implementation Issues Typically necessary to have multiple types of composites –Numbers and roles of composite parts Composite should protect its internal data structure –If necessary, give client iterator over component parts Maximize the abstract interface for client isolation –Provide all methods of all derived classes –Isolates client from needing to type cast to get what they need

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Composite Design Pattern (9) –Implementation Issues Where should we declare the “child management” methods? –For example – addChild, removeChild, … –Option I : in the Component class »again, isolates client from distinction »costs safety, meaningless to add to leaf »can add default behavior for all composites –Option II: in the Composite class »Safe – only defined on composites »Creates different interfaces for leaf and composites »Can provide “isComposite” to help with safe type casting

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Composite Design Pattern (10) –Implementation Issues Don’t declare “child list” in Component –tempting if child management introduced at this level –costs space in all leaf nodes Pointers to parents –Makes certain kinds of traversal easier

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Composite Design Pattern (11) –Example: Kaleidoscope Could support Shapes built from other shapes Sample Code public abstract class Shape {... } public class CompositeShape { protected Vector parts; public void addPart(Shape s){…} public void draw(Graphics g){ for(int i=0 ; i<parts.size(); i++){ ((Shape)(parts.get(i))).draw(g); }... Example of when to not use “final”

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Composite Design Pattern (12) –Common Variations None –Java API Usage java.awt.Component