SlideShare une entreprise Scribd logo
1  sur  23
Composite Design Pattern ,[object Object],[object Object],[object Object]
Design Patterns All  well-structured object-oriented systems  are  full of patterns . If the common collaborations among the objects of a complex object-oriented system is paid careful and sufficient attention, it can yield an architecture that is smaller, simpler and far more understandable Creational Structural Behavioral Abstract Factory Builder Prototype Singleton etc. Adapter Bridge Composite Decorator Façade Proxy etc. Command Iterator Observer Strategy Interpreter Mediator etc.
Structural  Design  Patterns ,[object Object],[object Object],May 23, 2007
What are Composite Objects ?? ,[object Object],[object Object],[object Object],[object Object],May 23, 2007
Problems handling primitives and composites ,[object Object],[object Object],[object Object],May 23, 2007
Why Composite Design Pattern ?? ,[object Object],[object Object],May 23, 2007
Why Composite Design Pattern ?? (cont.) ,[object Object],[object Object],May 23, 2007
Composite Pattern - Formal Definition ,[object Object],[object Object],May 23, 2007
A simple example May 23, 2007 Arithmetic expressions  are Composites. An arithmetic expression consists of an operand,  an operator ( +, -, *, / ) and another operand.  The operand can be a number, or another arithmetic expression . Thus, 2 + 3 and (2 + 3) + (4 * 6) are both valid expressions.
Composite Pattern – Class Diagram May 23, 2007
Collaborations May 23, 2007 The clients handle a component through its  general interface . A leaf directly executes the operations required, whereas a composite transfers the requests to its children.
An Example : File System ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],May 23, 2007
Example Continued… May 23, 2007 public void ls() { System.out.println(mName + “  ” ); for (int i=0; i<mFiles.size(); i++) { Object obj = mFiles.get(i); /* **** Recover the type of this object ****** */ if (obj.getClass().getName().equals( &quot;Directory&quot; )) ((Directory) obj).ls(); else ((File) obj).ls(); } } /* -- Some other methods here including add() -- */  } So here, we had to query the  &quot;type&quot;  of each object before attempting to process it, but it is  not desirable .
Can we use Composite Pattern here ?? May 23, 2007 The key to this composite pattern is an  interface  (AbstractFile) that represents both primitives(File) and composites (Directory).
Using Composite Pattern… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],May 23, 2007
Using Composite Pattern… (cont.) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],May 23, 2007
Another Example – Graphics Drawing May 23, 2007 In graphics applications, the user can group components to form larger components
Some more examples ,[object Object],[object Object],[object Object],May 23, 2007
Benefits ,[object Object],[object Object],[object Object],May 23, 2007
Some Implementation Issues ,[object Object],[object Object],May 23, 2007
Some Implementation Issues (cont.) ,[object Object],[object Object],May 23, 2007
Some Implementation Issues (cont.) ,[object Object],May 23, 2007
Thank You

Contenu connexe

Tendances

Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
Sara Torkey
 
Structural Design pattern - Adapter
Structural Design pattern - AdapterStructural Design pattern - Adapter
Structural Design pattern - Adapter
Manoj Kumar
 

Tendances (20)

Flyweight pattern
Flyweight patternFlyweight pattern
Flyweight pattern
 
Design Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternDesign Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory Pattern
 
Creational pattern
Creational patternCreational pattern
Creational pattern
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern Presentation
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Design Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternDesign Pattern - Factory Method Pattern
Design Pattern - Factory Method Pattern
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
 
Introduction to Design Pattern
Introduction to Design  PatternIntroduction to Design  Pattern
Introduction to Design Pattern
 
Structural Design pattern - Adapter
Structural Design pattern - AdapterStructural Design pattern - Adapter
Structural Design pattern - Adapter
 
Mediator pattern
Mediator patternMediator pattern
Mediator pattern
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Facade pattern presentation(.pptx)
Facade pattern presentation(.pptx)Facade pattern presentation(.pptx)
Facade pattern presentation(.pptx)
 
Design pattern
Design patternDesign pattern
Design pattern
 
Presentation facade design pattern
Presentation facade design patternPresentation facade design pattern
Presentation facade design pattern
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Observer Software Design Pattern
Observer Software Design Pattern Observer Software Design Pattern
Observer Software Design Pattern
 

Similaire à Composite Design Pattern

M04 Design Patterns
M04 Design PatternsM04 Design Patterns
M04 Design Patterns
Dang Tuan
 
Mapping objects to_relational_databases
Mapping objects to_relational_databasesMapping objects to_relational_databases
Mapping objects to_relational_databases
Ivan Paredes
 
Object Oriented Approach Within Siebel Boundaries
Object Oriented Approach Within Siebel BoundariesObject Oriented Approach Within Siebel Boundaries
Object Oriented Approach Within Siebel Boundaries
Roman Agaev
 

Similaire à Composite Design Pattern (20)

Sda 9
Sda   9Sda   9
Sda 9
 
Advance oops concepts
Advance oops conceptsAdvance oops concepts
Advance oops concepts
 
M04 Design Patterns
M04 Design PatternsM04 Design Patterns
M04 Design Patterns
 
PATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design PatternsPATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design Patterns
 
Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
 
UML
UMLUML
UML
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#
 
Data Structure.pptx
Data Structure.pptxData Structure.pptx
Data Structure.pptx
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pd
 
Bp301
Bp301Bp301
Bp301
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Software Patterns
Software PatternsSoftware Patterns
Software Patterns
 
Mapping objects to_relational_databases
Mapping objects to_relational_databasesMapping objects to_relational_databases
Mapping objects to_relational_databases
 
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScript
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScriptLotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScript
Lotusphere 2007 BP301 Advanced Object Oriented Programming for LotusScript
 
Slides chapter 11
Slides chapter 11Slides chapter 11
Slides chapter 11
 
Object Oriented Approach Within Siebel Boundaries
Object Oriented Approach Within Siebel BoundariesObject Oriented Approach Within Siebel Boundaries
Object Oriented Approach Within Siebel Boundaries
 
Structural pattern 3
Structural pattern 3Structural pattern 3
Structural pattern 3
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
CSc investigatory project
CSc investigatory projectCSc investigatory project
CSc investigatory project
 
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
 

Plus de Ferdous Mahmud Shaon (6)

Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven Development
 
Tips to Kick-start your Software Engineering Career
Tips to Kick-start your Software Engineering CareerTips to Kick-start your Software Engineering Career
Tips to Kick-start your Software Engineering Career
 
Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSS
 
Business Communcation
Business CommuncationBusiness Communcation
Business Communcation
 
Effective Java - Override clone() method judiciously
Effective Java - Override clone() method judiciouslyEffective Java - Override clone() method judiciously
Effective Java - Override clone() method judiciously
 
Effective Java - Always override toString() method
Effective Java - Always override toString() methodEffective Java - Always override toString() method
Effective Java - Always override toString() method
 

Dernier

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Dernier (20)

Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 

Composite Design Pattern

  • 1.
  • 2. Design Patterns All well-structured object-oriented systems are full of patterns . If the common collaborations among the objects of a complex object-oriented system is paid careful and sufficient attention, it can yield an architecture that is smaller, simpler and far more understandable Creational Structural Behavioral Abstract Factory Builder Prototype Singleton etc. Adapter Bridge Composite Decorator Façade Proxy etc. Command Iterator Observer Strategy Interpreter Mediator etc.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9. A simple example May 23, 2007 Arithmetic expressions are Composites. An arithmetic expression consists of an operand, an operator ( +, -, *, / ) and another operand. The operand can be a number, or another arithmetic expression . Thus, 2 + 3 and (2 + 3) + (4 * 6) are both valid expressions.
  • 10. Composite Pattern – Class Diagram May 23, 2007
  • 11. Collaborations May 23, 2007 The clients handle a component through its general interface . A leaf directly executes the operations required, whereas a composite transfers the requests to its children.
  • 12.
  • 13. Example Continued… May 23, 2007 public void ls() { System.out.println(mName + “ ” ); for (int i=0; i<mFiles.size(); i++) { Object obj = mFiles.get(i); /* **** Recover the type of this object ****** */ if (obj.getClass().getName().equals( &quot;Directory&quot; )) ((Directory) obj).ls(); else ((File) obj).ls(); } } /* -- Some other methods here including add() -- */ } So here, we had to query the &quot;type&quot; of each object before attempting to process it, but it is not desirable .
  • 14. Can we use Composite Pattern here ?? May 23, 2007 The key to this composite pattern is an interface (AbstractFile) that represents both primitives(File) and composites (Directory).
  • 15.
  • 16.
  • 17. Another Example – Graphics Drawing May 23, 2007 In graphics applications, the user can group components to form larger components
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.