SlideShare a Scribd company logo
COMPOSITE DESIGN PATTERN
KHURAM SHAHZAD 15034198-002
SOBIA PERVAIZ 15034198-021
M.FARHAN ASLAM 15034198-048
AYESHA MASOOD 13014198-019
THE COMPOSITE DESIGN PATTERN
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
THE COMPOSITE DESIGN PATTERN
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
THE COMPOSITE DESIGN PATTERN
Non-software example
• Arithmetic Expressions
• Operations can be applied
to terminals and composites
alike
THE COMPOSITE DESIGN PATTERN
Abstract Description
• Object Design Pattern
THE COMPOSITE DESIGN PATTERN
Abstract Description
• Sequence Diagram
Client Component Leaf1
operation
Leaf2 Composite
operation
operation
operation
THE COMPOSITE DESIGN PATTERN
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()
MachineCompositeMachine
getMachineCount()
THE COMPOSITE DESIGN PATTERN
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
THE COMPOSITE DESIGN PATTERN
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
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
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
THE COMPOSITE DESIGN PATTERN
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);
}
. . .
THE COMPOSITE DESIGN PATTERN
Common Variations
• None
Java API Usage
• java.awt.Component
Thank You For
Listening Carefully
Khuram Shahzad 15034198-002
Sobia Pervaiz 15034198-021
M.Farhan Aslam 15034198-048
Ayesha Masood 13014198-019
HAVE YOU ANY QUESTION
YOU CAN ASK

More Related Content

What's hot

Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
Shahzad
 
Facade pattern
Facade patternFacade pattern
Facade pattern
JAINIK PATEL
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
Shakil Ahmed
 
Design Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternDesign Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory Pattern
Mudasir Qazi
 
Abstract Factory Design Pattern
Abstract Factory Design PatternAbstract Factory Design Pattern
Abstract Factory Design Pattern
Bharat Khatri
 
Design Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternDesign Pattern - Factory Method Pattern
Design Pattern - Factory Method Pattern
Mudasir Qazi
 
Struts framework
Struts frameworkStruts framework
Observer pattern
Observer patternObserver pattern
Observer pattern
Shakil Ahmed
 
Proxy pattern
Proxy patternProxy pattern
Proxy pattern
Shakil Ahmed
 
Design patterns
Design patternsDesign patterns
Design patterns
abhisheksagi
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
naveen kumar
 
Bridge Design Pattern
Bridge Design PatternBridge Design Pattern
Bridge Design Pattern
Shahriar Hyder
 
Java Course 11: Design Patterns
Java Course 11: Design PatternsJava Course 11: Design Patterns
Java Course 11: Design Patterns
Anton Keks
 
09 package diagram
09 package diagram09 package diagram
09 package diagram
Baskarkncet
 
Adapter pattern
Adapter patternAdapter pattern
Adapter pattern
Shakil Ahmed
 
7.data types in c#
7.data types in c#7.data types in c#
7.data types in c#
Zeeshan Ahmad
 
EER modeling
EER modelingEER modeling
EER modeling
Dabbal Singh Mahara
 
Chain of responsibility
Chain of responsibilityChain of responsibility
Chain of responsibility
Shakil Ahmed
 
Abstraction and Encapsulation
Abstraction and EncapsulationAbstraction and Encapsulation
Abstraction and Encapsulation
Cheezy Code
 
Presentation facade design pattern
Presentation facade design patternPresentation facade design pattern
Presentation facade design pattern
Bayu Firmawan Paoh
 

What's hot (20)

Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
 
Facade pattern
Facade patternFacade pattern
Facade pattern
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
 
Design Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternDesign Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory Pattern
 
Abstract Factory Design Pattern
Abstract Factory Design PatternAbstract Factory Design Pattern
Abstract Factory Design Pattern
 
Design Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternDesign Pattern - Factory Method Pattern
Design Pattern - Factory Method Pattern
 
Struts framework
Struts frameworkStruts framework
Struts framework
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Proxy pattern
Proxy patternProxy pattern
Proxy pattern
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
 
Bridge Design Pattern
Bridge Design PatternBridge Design Pattern
Bridge Design Pattern
 
Java Course 11: Design Patterns
Java Course 11: Design PatternsJava Course 11: Design Patterns
Java Course 11: Design Patterns
 
09 package diagram
09 package diagram09 package diagram
09 package diagram
 
Adapter pattern
Adapter patternAdapter pattern
Adapter pattern
 
7.data types in c#
7.data types in c#7.data types in c#
7.data types in c#
 
EER modeling
EER modelingEER modeling
EER modeling
 
Chain of responsibility
Chain of responsibilityChain of responsibility
Chain of responsibility
 
Abstraction and Encapsulation
Abstraction and EncapsulationAbstraction and Encapsulation
Abstraction and Encapsulation
 
Presentation facade design pattern
Presentation facade design patternPresentation facade design pattern
Presentation facade design pattern
 

Similar to Composite design pattern

SADP PPTs of all modules - Shanthi D.L.pdf
SADP PPTs of all modules - Shanthi D.L.pdfSADP PPTs of all modules - Shanthi D.L.pdf
SADP PPTs of all modules - Shanthi D.L.pdf
B.T.L.I.T
 
Model view-delegates-whitepaper
Model view-delegates-whitepaperModel view-delegates-whitepaper
Model view-delegates-whitepaper
nilus
 
Facade Design Pattern
Facade Design PatternFacade Design Pattern
Facade Design Pattern
S. M. Masoud Sadrnezhaad
 
Vb net xp_13
Vb net xp_13Vb net xp_13
Vb net xp_13
Niit Care
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
Gaurav Tyagi
 
OOP.pptx
OOP.pptxOOP.pptx
OOP.pptx
saifnasir3
 
unit 1 &2.pdf
unit 1 &2.pdfunit 1 &2.pdf
unit 1 &2.pdf
Dr.P. SenthilKumar
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptx
anguraju1
 
IoT and Cloud Computing in Automation Application
IoT and Cloud Computing in Automation ApplicationIoT and Cloud Computing in Automation Application
IoT and Cloud Computing in Automation Application
Areej Qasrawi
 
MoDELS'16 presentation: Integration of a Graph-Based Model Indexer in Commerc...
MoDELS'16 presentation: Integration of a Graph-Based Model Indexer in Commerc...MoDELS'16 presentation: Integration of a Graph-Based Model Indexer in Commerc...
MoDELS'16 presentation: Integration of a Graph-Based Model Indexer in Commerc...
Antonio García-Domínguez
 
Vocational training on catia software
Vocational training on catia softwareVocational training on catia software
Vocational training on catia software
Piyush Verma
 
pyjamas22_ generic composite in python.pdf
pyjamas22_ generic composite in python.pdfpyjamas22_ generic composite in python.pdf
pyjamas22_ generic composite in python.pdf
Asher Sterkin
 
IPE 493_T6_Facility Layout.pptx
IPE 493_T6_Facility Layout.pptxIPE 493_T6_Facility Layout.pptx
IPE 493_T6_Facility Layout.pptx
ShaownRahmanSaidur
 
CAD/CAM/CIM (18ME72) Module-5 Part-A
CAD/CAM/CIM  (18ME72) Module-5 Part-ACAD/CAM/CIM  (18ME72) Module-5 Part-A
CAD/CAM/CIM (18ME72) Module-5 Part-A
Mohammed Imran
 
Object oriented sad-5 part i
Object oriented sad-5 part iObject oriented sad-5 part i
Object oriented sad-5 part i
Bisrat Girma
 
Pratk kambe rac
Pratk kambe racPratk kambe rac
Pratk kambe rac
Pratik Kambe
 
Day5
Day5Day5
An Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHPAn Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHP
Chris Renner
 
Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
JOSEPHINEA6
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)
Vu Tran Lam
 

Similar to Composite design pattern (20)

SADP PPTs of all modules - Shanthi D.L.pdf
SADP PPTs of all modules - Shanthi D.L.pdfSADP PPTs of all modules - Shanthi D.L.pdf
SADP PPTs of all modules - Shanthi D.L.pdf
 
Model view-delegates-whitepaper
Model view-delegates-whitepaperModel view-delegates-whitepaper
Model view-delegates-whitepaper
 
Facade Design Pattern
Facade Design PatternFacade Design Pattern
Facade Design Pattern
 
Vb net xp_13
Vb net xp_13Vb net xp_13
Vb net xp_13
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 
OOP.pptx
OOP.pptxOOP.pptx
OOP.pptx
 
unit 1 &2.pdf
unit 1 &2.pdfunit 1 &2.pdf
unit 1 &2.pdf
 
UNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptxUNIT IV DESIGN PATTERNS.pptx
UNIT IV DESIGN PATTERNS.pptx
 
IoT and Cloud Computing in Automation Application
IoT and Cloud Computing in Automation ApplicationIoT and Cloud Computing in Automation Application
IoT and Cloud Computing in Automation Application
 
MoDELS'16 presentation: Integration of a Graph-Based Model Indexer in Commerc...
MoDELS'16 presentation: Integration of a Graph-Based Model Indexer in Commerc...MoDELS'16 presentation: Integration of a Graph-Based Model Indexer in Commerc...
MoDELS'16 presentation: Integration of a Graph-Based Model Indexer in Commerc...
 
Vocational training on catia software
Vocational training on catia softwareVocational training on catia software
Vocational training on catia software
 
pyjamas22_ generic composite in python.pdf
pyjamas22_ generic composite in python.pdfpyjamas22_ generic composite in python.pdf
pyjamas22_ generic composite in python.pdf
 
IPE 493_T6_Facility Layout.pptx
IPE 493_T6_Facility Layout.pptxIPE 493_T6_Facility Layout.pptx
IPE 493_T6_Facility Layout.pptx
 
CAD/CAM/CIM (18ME72) Module-5 Part-A
CAD/CAM/CIM  (18ME72) Module-5 Part-ACAD/CAM/CIM  (18ME72) Module-5 Part-A
CAD/CAM/CIM (18ME72) Module-5 Part-A
 
Object oriented sad-5 part i
Object oriented sad-5 part iObject oriented sad-5 part i
Object oriented sad-5 part i
 
Pratk kambe rac
Pratk kambe racPratk kambe rac
Pratk kambe rac
 
Day5
Day5Day5
Day5
 
An Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHPAn Introduction to Domain Driven Design in PHP
An Introduction to Domain Driven Design in PHP
 
Vb6.0 intro
Vb6.0 introVb6.0 intro
Vb6.0 intro
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)
 

More from MUHAMMAD FARHAN ASLAM

Vocal guidance
Vocal guidanceVocal guidance
Vocal guidance
MUHAMMAD FARHAN ASLAM
 
Sanity testing and smoke testing
Sanity testing and smoke testingSanity testing and smoke testing
Sanity testing and smoke testing
MUHAMMAD FARHAN ASLAM
 
Memo writing
Memo writingMemo writing
Memo writing
MUHAMMAD FARHAN ASLAM
 
Good vs Bad
Good vs BadGood vs Bad
Library management system
Library management systemLibrary management system
Library management system
MUHAMMAD FARHAN ASLAM
 
Education Guidance and Counseling
Education Guidance and CounselingEducation Guidance and Counseling
Education Guidance and Counseling
MUHAMMAD FARHAN ASLAM
 
Education Guidance and Counseling
Education Guidance and CounselingEducation Guidance and Counseling
Education Guidance and Counseling
MUHAMMAD FARHAN ASLAM
 
Software Maintenance
Software MaintenanceSoftware Maintenance
Software Maintenance
MUHAMMAD FARHAN ASLAM
 
Memo
MemoMemo

More from MUHAMMAD FARHAN ASLAM (9)

Vocal guidance
Vocal guidanceVocal guidance
Vocal guidance
 
Sanity testing and smoke testing
Sanity testing and smoke testingSanity testing and smoke testing
Sanity testing and smoke testing
 
Memo writing
Memo writingMemo writing
Memo writing
 
Good vs Bad
Good vs BadGood vs Bad
Good vs Bad
 
Library management system
Library management systemLibrary management system
Library management system
 
Education Guidance and Counseling
Education Guidance and CounselingEducation Guidance and Counseling
Education Guidance and Counseling
 
Education Guidance and Counseling
Education Guidance and CounselingEducation Guidance and Counseling
Education Guidance and Counseling
 
Software Maintenance
Software MaintenanceSoftware Maintenance
Software Maintenance
 
Memo
MemoMemo
Memo
 

Recently uploaded

Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
gowrishankartb2005
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
Anant Corporation
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
Gino153088
 
Seminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptxSeminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptx
Madan Karki
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
SakkaravarthiShanmug
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 
People as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimalaPeople as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimala
riddhimaagrawal986
 
Design and optimization of ion propulsion drone
Design and optimization of ion propulsion droneDesign and optimization of ion propulsion drone
Design and optimization of ion propulsion drone
bjmsejournal
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
TaghreedAltamimi
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
GauravCar
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
ecqow
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
ElakkiaU
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
PKavitha10
 

Recently uploaded (20)

Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
 
Seminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptxSeminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptx
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 
People as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimalaPeople as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimala
 
Design and optimization of ion propulsion drone
Design and optimization of ion propulsion droneDesign and optimization of ion propulsion drone
Design and optimization of ion propulsion drone
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
 

Composite design pattern

  • 1. COMPOSITE DESIGN PATTERN KHURAM SHAHZAD 15034198-002 SOBIA PERVAIZ 15034198-021 M.FARHAN ASLAM 15034198-048 AYESHA MASOOD 13014198-019
  • 2. THE COMPOSITE DESIGN PATTERN 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
  • 3. THE COMPOSITE DESIGN PATTERN 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
  • 4. THE COMPOSITE DESIGN PATTERN Non-software example • Arithmetic Expressions • Operations can be applied to terminals and composites alike
  • 5. THE COMPOSITE DESIGN PATTERN Abstract Description • Object Design Pattern
  • 6. THE COMPOSITE DESIGN PATTERN Abstract Description • Sequence Diagram Client Component Leaf1 operation Leaf2 Composite operation operation operation
  • 7. THE COMPOSITE DESIGN PATTERN 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() MachineCompositeMachine getMachineCount()
  • 8. THE COMPOSITE DESIGN PATTERN 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
  • 9. THE COMPOSITE DESIGN PATTERN 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
  • 10. 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
  • 11. 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
  • 12. THE COMPOSITE DESIGN PATTERN 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); } . . .
  • 13. THE COMPOSITE DESIGN PATTERN Common Variations • None Java API Usage • java.awt.Component
  • 14. Thank You For Listening Carefully Khuram Shahzad 15034198-002 Sobia Pervaiz 15034198-021 M.Farhan Aslam 15034198-048 Ayesha Masood 13014198-019
  • 15. HAVE YOU ANY QUESTION YOU CAN ASK