Patterns Composite Pattern. Patterns All designers use patterns. Patterns in solutions come from patterns in problems. "A pattern is a solution to a problem.

Slides:



Advertisements
Similar presentations
ANU COMP2110 Software Design in 2003 Lecture 16Slide 1 Lecture 16: Introduction to design patterns 1What are they? 2Where do they come from? 3Why study.
Advertisements

18-1 Verifying Object Behavior and Collaboration Role playing – the act of simulating object behavior and collaboration by acting out an object’s behaviors.
Design Patterns Examples of smart use of inheritance and polymorphism: Composite Pattern State Pattern FEN 2014UCN Teknologi/act2learn1.
Object-Oriented Design Patterns Composite Singleton State Observer … Autumn 2012UCN Technology: IT/Computer Science1.
Plab – Tirgul 12 Design Patterns
Stéphane Ducasse«ChapterNr».1 Selected Design Patterns Design Patterns are recurrent solutions to design problems They are pros and cons We already saw:
Design Patterns for Object Oriented systems CSC 515 Ashwin Dandwate.
Design Patterns Yes, they are important Robert Cotton April 23, 2009.
Fundamentals of Software Development 1Slide 1 Gang of Four The beginnings… The original “patterns” idea was from architecture – there are repeatable patterns.
(c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.
Design Patterns CS is not simply about programming
Design Patterns Daniel McClain. Background What are they?  Way of recording solutions to recurring design problems History  “A Pattern Language: Towns,
Ralph Johnson - University of Illinois1 Patterns: What They Are, and How to Write Them Ralph Johnson University of Illinois at Urbana-Champaign
James Tam Introduction To Design Patterns You will learn about design techniques that have been successfully applied to different scenarios.
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
Design Patterns Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson,Ralph Johnson and John Vlissides (The Gang of.
Software Design and Documentation Individual Presentation: Composite Pattern 9/11/03.
(c) 2010 University of California, Irvine – André van der Hoek1June 29, 2015 – 08:55:05 Informatics 122 Software Design II Lecture 8 André van der Hoek.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Builder A Creational Design Pattern A Presentation by Alex Bluhm And.
Design Patterns Alan Shalloway, James Trott, Design Patterns Explained, Addison-Wesley, Gamma, Helm, Johnson, Vlissides, Design Patterns, Elements.
Design Patterns Trends and Case Study John Hurst June 2005.
Cf.OBJECTIVE (ANZ) Design Patterns and Form Processing Jaime Metcher Software Architect, Centre for Innovation in Professional Learning, University of.
Design Patterns.
1 Copyright © 2014 Atego. Patterns INCOSE MBSE WG – Simon A. Perry - Atego.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
Chapter Five An Introduction to Design Patterns Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information.
Copyright © 2002, Systems and Computer Engineering, Carleton University Patterns.ppt * Object-Oriented Software Development Part 11.
January 12, Introduction to Design Patterns Tim Burke References: –Gamma, Erich, et. al. (AKA, The Gang of Four). Design Patterns: Elements of Reusable.
ANU COMP2110 Software Design in 2004 Lecture 15Slide 1 COMP2110 in 2004 Software Design Lecture 15: Software design patterns (2) 1What are design patterns?
Creational Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
CS 325: Software Engineering February 12, 2015 Applying Responsibility-Assignment Patterns Design Patterns Situation-Specific Patterns Responsibility-Assignment.
Behavioral Design Patterns Morteza Yousefi University Of Science & Technology Of Mazandaran 1of 27Behavioral Design Patterns.
Centralized vs. Decentralized Interpreter Pattern Visitor Pattern.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
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.
ECE450S – Software Engineering II
1 Design Patterns Object-Oriented Design. 2 Design Patterns 4Reuse of design knowledge and experience 4Common in many engineering disciplines 4Avoids.
05/26/2004www.indyjug.net1 Indy Java User’s Group May Knowledge Services, Inc.
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
Game Programming Patterns From the book by Robert Nystrom
Patterns Protect from Change Rule: if something is going to change, make it an object. Strategy: make algorithm an object so it can change State: make.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Design Patterns: MORE Examples
The Object-Oriented Thought Process Chapter 15
MPCS – Advanced java Programming
Common Design Patterns
Design Patterns Introduction
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2005 Instructor: Patrice Chalin.
Design Patterns - A few examples
Web Programming Language
Informatics 122 Software Design II
Patterns.
DESIGNING YOUR SYSTEM.
DESIGN PATTERNS : Introduction
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Design Patterns Imran Rashid CTO at ManiWeber Technologies.
Informatics 122 Software Design II
Composite Design Pattern By Aravind Reddy Patlola.
Presentation transcript:

Patterns Composite Pattern

Patterns All designers use patterns. Patterns in solutions come from patterns in problems. "A pattern is a solution to a problem in a context."

Christopher Alexander -- A Pattern Language "Each pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice."

Design Patterns: Elements of Reusable Object-Oriented Software Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides Addison-Wesley object-oriented patterns

Composite Context: Developing OO software Problem: Complex part-whole hierarchy has lots of similar classes. Example: document, chapter, section, paragraph.

Forces simplicity -- treat composition of parts like a part power -- create new kind of part by composing existing ones safety -- no special cases, treat everything the same

Composite Idea: make abstract "component" class. Alternative 1: every component has a (possibly empty) set of components. Problem: many components have no components. Component Children ParagraphChapter... *

Composite Pattern Component container childrenDo: CompositeLeaf Composite and Component have the exact same interface. enumerating children enumerating children childrenDo: for Component does nothing childrenDo: for Component does nothing only Composite adds removes children. only Composite adds removes children. *

Two design alternatives for Part-of Component does not know what it is a part of Component can be in many composite. Component can be accessed only through composite. Component knows what it is a part of Component can be in only one composite. Component can be accessed directly. :

Part-of Rules when component knows its single composite. A is a part of B if and only if B is the composite of A. Duplicating information is dangerous! Problem: how to ensure that pointers from components to composite and composite to components are consistent.

Ensuring Consistency The public operations on components and composites are: Composite can enumerate components. Component knows its container. Add/remove a component to/from the composite.

The operation to add a component to a composite updates the container of the component. There should be no other way to change the container of a component. In C++, make component friend of composite. Smalltalk does not enforce private methods.

private container: anObject container := anObject accessing addComponent: aComponent components add: aComponent aComponent container: self

Example: Views and Figures Big window can contain smaller windows.

Composite Pattern in VisualWorks VisualPart Container CompositePart VisualComponent Children ComposedText ListView Most operations in CompositePart iterate over the children and repeat the operation on them. *

CompositePart addComponent: aVisualComponent self isOpen ifTrue: [... ] ifFalse: [components addLast: aVisualComponent. aVisualComponent container: self]

displayOn: aContext "Display each component." | clipBox | clipBox := aContext clippingBounds. components do: [:each | (each intersects: clipBox) ifTrue: [each displayOn: aContext copy]]

Refactoring to a Composite CompoundLeaf Missing abstract class Missing leaf classes Element Class2Class3Class1 * *

Summary Pattern stretches from design to code Patterns vary

Start reading Design Patterns. Read Template Method, Iterator, Composite, Observer, Decorator, Command