Software Design Lecture : 36.

Slides:



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

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)
Iterators T.J. Niglio Computer & Systems Engineering Fall 2003 Software Design & Documentation Object Behavioral.
7M701 1 Class Diagram advanced concepts. 7M701 2 Characteristics of Object Oriented Design (OOD) objectData and operations (functions) are combined 
Software Design and Documentation Individual Presentation: Composite Pattern 9/11/03.
7M822 UML Class Diagrams advanced concepts 15 September 2008.
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.
Databases Illuminated Chapter 7 The Object-Oriented Model.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
The Unified Modeling Language (UML) Class Diagrams.
1 Dept. of Computer Science & Engineering, York University, Toronto Software Development CSE3311 Composite Pattern.
CS 2511 Fall UML Diagram Types  2 Main Types Structure Diagrams ○ Class Diagrams ○ Component Diagrams ○ Object Diagrams Behavior Diagrams ○
1 PH Chapter 1 (pp. 1-10) GoF Composite Pattern (pp ) PH Ch 2 through Fundamentals (pp ) Presentation by Julie Betlach 5/28/2009.
Object Based Programming. Summary Slide  Instantiating An Object  Encapsulation  Inheritance  Polymorphism –Overriding Methods –Overloading vs. Overriding.
Composite Design Pattern. Motivation – Dynamic Structure.
Classes and objects Practice 2. Basic terms  Classifier is an element of the model, which specifies some general features for a set of objects. Features.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Composit Pattern.
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.
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,
Object-Oriented Modeling Chapter 10 CSCI CSCI 1302 – Object-Oriented Modeling2 Outline The Software Development Process Discovering Relationships.
Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.
Lab 04.
Chapter 16 Applying UML and Patterns Craig Larman
The Static Analysis Model Class Diagrams Prof. Hany H. Ammar, CSEE, WVU, and Dept. of Computer Science, Faculty of Computers and Information, Cairo University.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
Structural Design Patterns
Object Oriented Analysis and Design Class and Object Diagrams.
Composite and Related Patterns Kirk Scott. The pitohui, a poisonous bird of New Guinea.
Entity-Relation Model. E-R Model The Entity-Relationship (ER) model was originally proposed by Peter in 1976 ER model is a conceptual data model that.
Object-Oriented Programming © 2013 Goodrich, Tamassia, Goldwasser1Object-Oriented Programming.
CS212: Object Oriented Analysis and Design Lecture 39: Design Pattern-III.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
The Interpreter Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Reference – Object Oriented Software Development Using Java - Jia COP 3331 Object Oriented Analysis and Design Chapter 10 – Patterns Jean Muhammad.
CLASS DIAGRAMS A classy approach to objects. The Basic Class Diagram  Class Name  Attributes (- indicates private each would have properties or accessor/mutator.
Object-Oriented Programming: Polymorphism Chapter 10.
D ESIGN P ATTERNS Vasanth Raja Chittampally
COMPOSITE PATTERN NOTES. The Composite pattern l Intent Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients.
Computer Science 313 – Advanced Programming Topics.
ISC321 Database Systems I Chapter 2: Overview of Database Languages and Architectures Fall 2015 Dr. Abdullah Almutairi.
Software Modelling Class Diagram. Class Diagrams The main building block in object oriented modeling They are used both for general conceptual modeling.
Command Pattern. Intent encapsulate a request as an object  can parameterize clients with different requests, queue or log requests, support undoable.
Composite Pattern Himanshu Gupta Shashank Hegde CSE776 – Design Patterns Fall 2011 Good composition is like a suspension bridge - each line adds strength.
Design Patterns Partha Kuchana, Software Architecture Design Patterns in Java, Auerbach Publications, 2004.
Topic 2: binary Trees COMP2003J: Data Structures and Algorithms 2
P802.1CF Information Model Structure
Object-Orientated Analysis, Design and Programming
UofC Large Display Framework
Composite Design Pattern
Composite Pattern SE2811 Software Component Design
Iterator and Composite Design Patterns
Chapter 2: Database System Concepts and Architecture
Design Patterns - A few examples
Object Oriented Analysis and Design
Jim Fawcett CSE776 – Design Patterns Summer 2003
Packages and Interfaces
Databases and Structured Files: What is a database?
13. Composite Pattern SE2811 Software Component Design
Software Design Lecture : 35.
13. Composite Pattern SE2811 Software Component Design
Composite Design Pattern By Aravind Reddy Patlola.
Software Design Lecture : 39.
Software Design Lecture : 28.
Relationships—Topics
Presentation transcript:

Software Design Lecture : 36

Composite Design Pattern

Motivation for Composite Design Pattern Every component or object can be classified into one of the two categories — Individual Components Composite Components — which are composed of individual components or other composite components

Intend of Composite Design Pattern To have a common interface for both individual and composite components so that client programs can view both the individual components and groups of components uniformly. Usually a Tree structure having nodes and leave nodes represents composite and individual components respectively.

Discussion on Whole-Part relation

Aggregation or “ has –a “ relationship Specialized form of association i-e Weak Association. Assembling a class from other classes. Aggregation is a special type of relationship used to model a "whole to its parts" relationship Part class is independent from the whole class's lifecycle.

Aggregation In an aggregation relationship, the child class instance can outlive its parent class. Child class can be a part of multiple parent classes. To represent an aggregation relationship, you draw a solid line from the parent class to the part class, and draw an unfilled diamond shape on the parent class's association end

Example

Aggregation Example

Tree Structure Revisited

Discussion on Vector

Composite Pattern Defined Composite Design pattern allow us to compose objects into tree structures to represent whole- part hierarchy . It let the client handle the composite and individual components in a uniform manner

Class Diagram of Composite Design Pattern

Example of Composite Pattern Let us create an application to simulate the Windows/UNIX file system. The file system consists mainly of two types of components — directories and files. Directories can be made up of other directories or files, whereas files cannot contain any other file system component. In this aspect, directories act as nonterminal nodes and files act as terminal nodes or leaf node of a tree structure.

Design Approach Let us define a common interface for both directories and files in the form of a Java interface FileSystemComponent The FileSystemComponent interface declares methods that are common for both file components and directory components. Let us further define two classes — FileComponent and DirComponent — as implementers of the common FileSystemComponent interface as shown in next slide

Class Diagram of Proposed Approach

Description of Classes FileComponent The FileComponent class represents a file in the file system and offers implementation for the following methods. getComponentSize() This method returns the size (in kilobytes) of the file represented by the File- Component object.

Class Descriptions DirComponent This class represents a directory in the file system. Since directories are composite entities, the DirComponent provides methods to deal with the components it contains. These methods are in addition to the common getComponentSize method declared in the FileSystemComponent interface.

Class Description addComponent(FileSystemComponent) This method is used by client applications to add different DirComponent and FileComponent objects to a DirComponent object. getComponent(int) The DirComponent stores the other FileSystemComponent objects inside a vector. This method is used to retrieve one such object stored at the specified location.

Class Description getComponentSize() This method returns the size (in kilobytes) of the directory represented by the DirComponent object. As part of the implementation, the DirComponent object iterates over the collection of FileSystemComponent objects it contains, in a recursive manner, and sums up the sizes of all individual FileComponents. The final sum is returned as the size of the directory it represents.

Processing of Class Diagram A typical client would first create a set of FileSystemComponent objects (both DirComponent and FileComponent instances). It can use the addComponent method of the DirComponent to add different FileSystemComponents to a DirComponent, creating a hierarchy of file system (FileSystemComponent) objects.

Calculating the Size of Object When the client wants to query any of these objects for its size, it can simply invoke the getComponentSize method. The client does not have to be aware of the calculations involved or the manner in which the calculations are carried out in determining the component size. In this aspect, the client treats both the FileComponent and the DirComponent object in the same manner. No separate code is required to query FileComponent objects and DirComponent objects for their size.

Problem in Current Design Client to keep track when calling a non-common method like addcomponent and getcomponent as these methods exists only in DirComponent

Design Approach -II Provide the same advantage of allowing the client application to treat both the composite DirComponent and the individual FileComponent objects in a uniform manner while invoking the getComponentSize method

Code in Word File