Software Design and Documentation Individual Presentation: Composite Pattern 9/11/03.

Slides:



Advertisements
Similar presentations
GoF State Pattern Aaron Jacobs State(305) Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.
Advertisements

Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
Matt Klein. Decorator Pattern  Intent  Attach Additional responsibilities to an object by dynamically. Decorators provide a flexible alternative to.
1 Structural Design Patterns - Neeraj Ray. 2 Structural Patterns - Overview n Adapter n Bridge n Composite n Decorator.
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.
Stéphane Ducasse«ChapterNr».1 Selected Design Patterns Design Patterns are recurrent solutions to design problems They are pros and cons We already saw:
The Composite Pattern. Owners (No Twins, Expos) Managers (No Twins, Expos) Congress (No Twins, Expos) Media (No Twins, Expos) Radio (No Twins, Expos)
What is the Chain? It’s a behavioral design pattern. It deals with how objects make requests and how they are handled.
Iterators T.J. Niglio Computer & Systems Engineering Fall 2003 Software Design & Documentation Object Behavioral.
Design Patterns. CS351 - Software Engineering (AY2007)Slide 2 Behavioral patterns Suppose we have an aggregate data structure and we wish to access the.
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.
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.
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.
SE2811 Week 7, Class 1 Composite Pattern Applications Conceptual form Class structure Coding Example Lab Thursday: Quiz SE-2811 Slide design: Dr. Mark.
Design Pattern Interpreter By Swathi Polusani. What is an Interpreter? The Interpreter pattern describes how to define a grammar for simple languages,
© 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,
Pattern Hatching - John Vlissides Pages 85 – 101 Todd Anderson
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
CSE 403 Lecture 14 Design Patterns. Today’s educational objective Understand the basics of design patterns Be able to distinguish them from design approaches.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Structural Design Patterns
1 Design Patterns Object-Oriented Design. 2 Design Patterns 4Reuse of design knowledge and experience 4Common in many engineering disciplines 4Avoids.
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.
Chain of Responsibility Behavioral Pattern. Defination Avoid coupling between the sender and receiver by giving more than one object a chance to handle.
Design Patterns Introduction
Patterns Composite Pattern. Patterns All designers use patterns. Patterns in solutions come from patterns in problems. "A pattern is a solution to a problem.
CS212: Object Oriented Analysis and Design Lecture 39: Design Pattern-III.
The Visitor Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
1 Advanced Object-oriented Design – Principles and Patterns Structural Design Patterns.
COMPOSITE. Design Pattern Space Purpose ScopeCreationalStructuralBehavioral ClassFactory MethodAdapterInterpreter Template Method ObjectAbstract factory.
Reference – Object Oriented Software Development Using Java - Jia COP 3331 Object Oriented Analysis and Design Chapter 10 – Patterns Jean Muhammad.
Adaptor Bridge Composite UNIT-IV1 Repeated key points for Structural Patterns (Intent, Motivation, Also Known As…) Code Examples Reference
Behavioural Patterns GoF pg Iterator GoF pg. 257 – 271 Memento GoF pg By: Dan Sibbernsen.
COMPOSITE PATTERN NOTES. The Composite pattern l Intent Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients.
Software Design and Architecture Muhammad Nasir Structural Design Patterns
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.
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Design Patterns Lecture part 2.
Composite Design Pattern
Flyweight Design Pattern
Composite Pattern SE2811 Software Component Design
Iterator and Composite Design Patterns
Object-Oriented Design
More Design Patterns 1.
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
13. Composite Pattern SE2811 Software Component Design
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
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Presentation transcript:

Software Design and Documentation Individual Presentation: Composite Pattern 9/11/03

Outline of Presentation 1. Intent 2. Motivation 3. Applicability 4. Structure 5. Participants 6. Collaborations 7. Consequences 8. Implementation 9. Known Uses 10. Related Patterns Follows outline of notes pages of Design Patterns Text.

What is a composite?

A structural pattern A structural pattern Used to “compose” objects into a tree structure hierarchy Used to “compose” objects into a tree structure hierarchy Used when individual objects and composites of objects are to be treated uniformly Used when individual objects and composites of objects are to be treated uniformly

Motivation Composites prevent the client from having to distinguish between primitive and container objects Composites prevent the client from having to distinguish between primitive and container objects Base of the composite structure is an abstract class that can represent both types of objects mentioned above Base of the composite structure is an abstract class that can represent both types of objects mentioned above –Ex.) Graphic Class

Applicability When “part-whole” hierarchies of objects are needed in software design When “part-whole” hierarchies of objects are needed in software design When clients desire to ignore the difference between composites and individual objects When clients desire to ignore the difference between composites and individual objects

Structure Composite Leaf Composite Leaf

Participants Component Component –Declares the interface for objects in the composition –Implements all default behaviors –Declares an interface for manipulating its child components –May define an interface for accessing a parent in a strucure

Participants Leaf Leaf –Represents a leaf object in the composition Ex.) Rectangle, Circle, Text… Ex.) Rectangle, Circle, Text… –Leaf means no children stem from this object –Defines primitive objects behaviors

Participants Composite Composite –Defines behaviors for components which will have children –Stores these child components –Implements all child related operations in the previously mentioned Component interface –Ex.) Picture

Participants Client Client –Uses the Component interface for object manipulation within the composite

Collaborations Clients use the Component interface to interact with the Composite structure. Clients use the Component interface to interact with the Composite structure. If leaf is receiver  request is handled directly If leaf is receiver  request is handled directly If composite is receiver  forward request to child components (operations may be performed before or after forwarding. If composite is receiver  forward request to child components (operations may be performed before or after forwarding.

Consequences Primitive and composite objects are defined in a class hierarchy. Primitive and composite objects are defined in a class hierarchy. The process of “composing” a primitive object into a composite object occurs over and over recursively. The process of “composing” a primitive object into a composite object occurs over and over recursively. By treating primitive and composite objects uniformly, client is simplified. By treating primitive and composite objects uniformly, client is simplified. Easy to add new components. Easy to add new components. MAY MAKE DESIGN OVERLY GENERAL! MAY MAKE DESIGN OVERLY GENERAL! –Difference in handling composite and primitive obj.

Implementation Explicit parent references Explicit parent references Sharing Components Sharing Components Maximizing the Component interface Maximizing the Component interface Declaring the child management operations Declaring the child management operations List of Components? List of Components? Child Ordering Child Ordering Caching Caching Who should delete components Who should delete components Best data Structure? Best data Structure?

Explicit Parent Referencing Simplifies traversal while moving up structure Simplifies traversal while moving up structure Supports the “chain of responsibility” pattern Supports the “chain of responsibility” pattern Parents are defined in component class Parents are defined in component class Parents are changed only in the add and remove operations Parents are changed only in the add and remove operations

Sharing Components Children can store multiple parents to allow for component sharing. Children can store multiple parents to allow for component sharing.

Maximizing Component Interface Defines as many common operations between leaf and composite as possible. Defines as many common operations between leaf and composite as possible. Leaf and composite sub classes can overload default operations from component class Leaf and composite sub classes can overload default operations from component class

Declaring Child Management Operations Where to define add or remove? Where to define add or remove? For transparency, define class at root of hierarchy  allows all component classes uniform treatment. For transparency, define class at root of hierarchy  allows all component classes uniform treatment. For safety, define in composite class so all attempts to add/remove are caught during compile/run time. Transparency is lost because now leaf and composite have different interfaces For safety, define in composite class so all attempts to add/remove are caught during compile/run time. Transparency is lost because now leaf and composite have different interfaces

List of components For component to implement a list of components, there should be very few children, otherwise the space penalty will be incurred every time a new leaf is created. For component to implement a list of components, there should be very few children, otherwise the space penalty will be incurred every time a new leaf is created.

Child ordering Not necessarily an issue, but for some composites like the graphics class, ordering may represent a “front-to-back” structure and necessary operations need to be made to arrange the children properly. Not necessarily an issue, but for some composites like the graphics class, ordering may represent a “front-to-back” structure and necessary operations need to be made to arrange the children properly.

Caching Caching can improve performance by caching certain search queries if the structure is going to be traversed multiple times. Caching can improve performance by caching certain search queries if the structure is going to be traversed multiple times.

Who should delete components? If the language being used does not support garbage collection, make the composite class responsible, otherwise let the garbage collection classes take care of the problem. If the language being used does not support garbage collection, make the composite class responsible, otherwise let the garbage collection classes take care of the problem.

Best data structure? Pick the most efficient structure to store your child lists following the rules as usual for vectors, trees, linked lists, etc. Pick the most efficient structure to store your child lists following the rules as usual for vectors, trees, linked lists, etc.

Sample Code class Equipment{ class Equipment{ public: public: virtual ~Equipment(); virtual ~Equipment(); const char* Name() {return _name;} const char* Name() {return _name;} virtual Watt Power(); virtual Watt Power(); virtual Currency NetPrice(); virtual Currency NetPrice(); virtual Cureency Discount Price(); virtual Cureency Discount Price(); virtual void Add(Equipment*); virtual void Add(Equipment*); virtual void Remove(Equipment*); virtual void Remove(Equipment*); virtual Iterator * CreateIterator(); virtual Iterator * CreateIterator(); protected: protected: Equipment(const char*_name); Equipment(const char*_name); private: private: const char* _name; const char* _name; }; };

Known Uses Object oriented systems Object oriented systems –Smalltalk Model, View, Controller Primitive assignments that perform an operation on two registers and assign the result to a third. Primitive assignments that perform an operation on two registers and assign the result to a third. An assignment with a source register but no source (assigned before routine starts). An assignment with a source register but no source (assigned before routine starts).

Related Patterns Pg. 223, Chain of responsibility Pg. 223, Chain of responsibility Pg. 175, Decorator Pg. 175, Decorator Pg. 195, Flyweight Pg. 195, Flyweight Pg. 257, Iterator Pg. 257, Iterator Pg. 331, Visitor Pg. 331, Visitor

Questions

Bibliography Design Patterns, Gamma, Helm, Johnson, Vlissides. Addison-Wesley Pgs Design Patterns, Gamma, Helm, Johnson, Vlissides. Addison-Wesley Pgs