SlideShare una empresa de Scribd logo
1 de 14
Design Pattern
Chain of Responsibility
A behavioral design pattern

                                               Mosfiqur Rahman




                              Copyright © KAZ Software Limited
Intent
Avoid coupling the sender of a request to its receiver by giving more than
one object a chance to handle the request. Chain the receiving objects
and pass the request along the chain until an object handles it.




                                             Copyright © KAZ Software Limited
Motivation
Consider a context-sensitive help facility for a graphical user interface. The
user can obtain help information on any part of the interface just by clicking
on it. The help that's provided depends on the part of the interface that's
selected and its context; for example, a button widget in a dialog box might
have different help information than a similar button in the main window. If
no specific help information exists for that part of the interface, then the
help system should display a more general help message about the
immediate context—the dialog box as a whole, for example.




                                               Copyright © KAZ Software Limited
Motivation




             Copyright © KAZ Software Limited
Motivation
The idea of this pattern is to decouple senders and receivers by giving
multiple objects a chance to handle a request. The request gets passed
along a chain of objects until one of them handles it.
Let's assume the user clicks for help on a button widget marked "Print."
The button is contained in an instance of PrintDialog, which knows the
application object it belongs to (see preceding object diagram). The
following interaction diagram illustrates how the help request gets
forwarded along the chain:




                                             Copyright © KAZ Software Limited
Motivation
To forward the request along the chain, and to ensure receivers remain
implicit, each object on the chain shares a common interface for handling
requests and for accessing its successor on the chain. For example, the
help system might define a HelpHandler class with a corresponding
HandleHelp operation. HelpHandler can be the parent class for candidate
object classes, or it can be defined as a mixin class. Then classes that
want to handle help requests can make HelpHandler a parent.

The Button, Dialog, and Application classes use HelpHandler operations
to handle help requests. HelpHandler's HandleHelp operation forwards the
request to the successor by default. Subclasses can override this
operation to provide help under the right circumstances; otherwise they
can use the default implementation to forward the request.




                                            Copyright © KAZ Software Limited
Motivation
In this case, neither aPrintButton nor aPrintDialog handles the request; it
stops at anApplication, which can handle it or ignore it. The client that
issued the request has no direct reference to the object that ultimately
fulfills it.




                                              Copyright © KAZ Software Limited
Applicability
Use Chain of Responsibility when
• more than one object may handle a request, and the handler isn't known
a priori. The handler should be ascertained automatically.
• you want to issue a request to one of several objects without specifying
the receiver explicitly.
• the set of objects that can handle a request should be specified
dynamically.




                                             Copyright © KAZ Software Limited
Structure




A typical object structure might look like this:




                                                   Copyright © KAZ Software Limited
Participants
• Handler (HelpHandler)
     o defines an interface for handling requests.
     o (optional) implements the successor link.
• ConcreteHandler (PrintButton, PrintDialog)
     o handles requests it is responsible for.
     o can access its successor.
     o if the ConcreteHandler can handle the request, it does so;
     otherwise it forwards the request to its successor.
• Client
     o initiates the request to a ConcreteHandler object on the chain.




                                             Copyright © KAZ Software Limited
Collaborations
When a client issues a request, the request propagates along the chain
until a ConcreteHandler object takes responsibility for handling it.




                                           Copyright © KAZ Software Limited
Consequences
Chain of Responsibility has the following benefits and liabilities:
1. Reduced coupling. The pattern frees an object from knowing which
other object handles a request. An object only has to know that a request
will be handled "appropriately." Both the receiver and the sender have no
explicit knowledge of each other, and an object in the chain doesn't have to
know about the chain's structure.
As a result, Chain of Responsibility can simplify object interconnections.
Instead of objects maintaining references to all candidate receivers, they
keep a single reference to their successor.

2. Added flexibility in assigning responsibilities to objects. Chain of
Responsibility gives you added flexibility in distributing responsibilities
among objects. You can add or change responsibilities for handling a
request by adding to or otherwise changing the chain at run-time. You can
combine this with subclassing to specialize handlers statically.




                                             Copyright © KAZ Software Limited
Consequences
3. Receipt isn't guaranteed. Since a request has no explicit receiver,
there's no guarantee it'll be handled—the request can fall off the end of
the chain without ever being handled. A request can also go unhandled
when the chain is not configured properly.




                                              Copyright © KAZ Software Limited
Assignment
In the banking system where cheque's for clearing is approved by the
person but if the cheque amount is beyond certain limit, the approving
responsibility moves the person higher in authority in the bank. Design the
cheque approving system using the pattern in such a way that new limit
can be easily introduced in the system. Its up to you to decide the number
of default layers.




                                             Copyright © KAZ Software Limited

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Command pattern
Command patternCommand pattern
Command pattern
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern Presentation
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Chain of Responsibility Pattern
Chain of Responsibility PatternChain of Responsibility Pattern
Chain of Responsibility Pattern
 
Strategy Pattern
Strategy PatternStrategy Pattern
Strategy Pattern
 
Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
 
Iterator Design Pattern
Iterator Design PatternIterator Design Pattern
Iterator Design Pattern
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
 
DESIGN PATTERNS: Strategy Patterns
DESIGN PATTERNS: Strategy PatternsDESIGN PATTERNS: Strategy Patterns
DESIGN PATTERNS: Strategy Patterns
 
Design pattern - Facade Pattern
Design pattern - Facade PatternDesign pattern - Facade Pattern
Design pattern - Facade Pattern
 
Struts
StrutsStruts
Struts
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design Pattern
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Proxy pattern
Proxy patternProxy pattern
Proxy pattern
 
Facade Design Pattern
Facade Design PatternFacade Design Pattern
Facade Design Pattern
 
Bridge pattern
Bridge patternBridge pattern
Bridge pattern
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Builder pattern
Builder patternBuilder pattern
Builder pattern
 
Flyweight pattern
Flyweight patternFlyweight pattern
Flyweight pattern
 
Facade Pattern
Facade PatternFacade Pattern
Facade Pattern
 

Destacado

Strategy and Template Pattern
Strategy and Template PatternStrategy and Template Pattern
Strategy and Template PatternJonathan Simon
 
20120420 - Design pattern bridge
20120420 - Design pattern bridge20120420 - Design pattern bridge
20120420 - Design pattern bridgeLearningTech
 
Bridge Design Pattern
Bridge Design PatternBridge Design Pattern
Bridge Design Patternsahilrk911
 
MVC and Other Design Patterns
MVC and Other Design PatternsMVC and Other Design Patterns
MVC and Other Design PatternsJonathan Simon
 
PATTERNS03 - Behavioural Design Patterns
PATTERNS03 - Behavioural Design PatternsPATTERNS03 - Behavioural Design Patterns
PATTERNS03 - Behavioural Design PatternsMichael Heron
 
Command and Adapter Pattern
Command and Adapter PatternCommand and Adapter Pattern
Command and Adapter PatternJonathan Simon
 
Microclimate
MicroclimateMicroclimate
MicroclimateSHS Geog
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Patternguy_davis
 
Microclimate Factors
Microclimate FactorsMicroclimate Factors
Microclimate FactorsTrev
 
Descriptive statistics
Descriptive statisticsDescriptive statistics
Descriptive statisticsRajesh Gunesh
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design PatternAdeel Riaz
 
Software Design Patterns in Laravel by Phill Sparks
Software Design Patterns in Laravel by Phill SparksSoftware Design Patterns in Laravel by Phill Sparks
Software Design Patterns in Laravel by Phill SparksPhill Sparks
 

Destacado (20)

Mediator pattern
Mediator patternMediator pattern
Mediator pattern
 
Chain of Responsibility Pattern
Chain of Responsibility PatternChain of Responsibility Pattern
Chain of Responsibility Pattern
 
Bridge Pattern Derek Weeks
Bridge Pattern   Derek WeeksBridge Pattern   Derek Weeks
Bridge Pattern Derek Weeks
 
Strategy and Template Pattern
Strategy and Template PatternStrategy and Template Pattern
Strategy and Template Pattern
 
Bridge Pattern
Bridge PatternBridge Pattern
Bridge Pattern
 
20120420 - Design pattern bridge
20120420 - Design pattern bridge20120420 - Design pattern bridge
20120420 - Design pattern bridge
 
Bridge Design Pattern
Bridge Design PatternBridge Design Pattern
Bridge Design Pattern
 
Command Pattern
Command PatternCommand Pattern
Command Pattern
 
MVC and Other Design Patterns
MVC and Other Design PatternsMVC and Other Design Patterns
MVC and Other Design Patterns
 
PATTERNS03 - Behavioural Design Patterns
PATTERNS03 - Behavioural Design PatternsPATTERNS03 - Behavioural Design Patterns
PATTERNS03 - Behavioural Design Patterns
 
Command and Adapter Pattern
Command and Adapter PatternCommand and Adapter Pattern
Command and Adapter Pattern
 
Microclimate
MicroclimateMicroclimate
Microclimate
 
Dbn163 # 04. macro micro climate
Dbn163 # 04. macro micro climateDbn163 # 04. macro micro climate
Dbn163 # 04. macro micro climate
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Microclimate Factors
Microclimate FactorsMicroclimate Factors
Microclimate Factors
 
Bridge Design Pattern
Bridge Design PatternBridge Design Pattern
Bridge Design Pattern
 
Descriptive statistics
Descriptive statisticsDescriptive statistics
Descriptive statistics
 
2. Microclimate
2. Microclimate2. Microclimate
2. Microclimate
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Software Design Patterns in Laravel by Phill Sparks
Software Design Patterns in Laravel by Phill SparksSoftware Design Patterns in Laravel by Phill Sparks
Software Design Patterns in Laravel by Phill Sparks
 

Similar a Chain of responsibility

Ladies Be Architects - Study Group III: OAuth 2.0 (Ep 1)
Ladies Be Architects - Study Group III: OAuth 2.0 (Ep 1)Ladies Be Architects - Study Group III: OAuth 2.0 (Ep 1)
Ladies Be Architects - Study Group III: OAuth 2.0 (Ep 1)gemziebeth
 
Interview Questions For Microsoft Dynamics CRM
Interview Questions For Microsoft Dynamics CRMInterview Questions For Microsoft Dynamics CRM
Interview Questions For Microsoft Dynamics CRMKumari Warsha Goel
 
Test slideshow
Test slideshowTest slideshow
Test slideshowlegacye
 
Test slideshow
Test slideshowTest slideshow
Test slideshowlegacye
 
Test slideshow
Test slideshowTest slideshow
Test slideshowlegacye
 
Test slideshow
Test slideshowTest slideshow
Test slideshowlegacye
 
Web_based_content_management_system_using_crowdsourcing_technology
Web_based_content_management_system_using_crowdsourcing_technologyWeb_based_content_management_system_using_crowdsourcing_technology
Web_based_content_management_system_using_crowdsourcing_technologyChamil Chandrathilake
 
DescriptionThis assignment will involve a proposal for the des.docx
DescriptionThis assignment will involve a proposal for the des.docxDescriptionThis assignment will involve a proposal for the des.docx
DescriptionThis assignment will involve a proposal for the des.docxsimonithomas47935
 
PRShare: a framework for privacy-preserving, interorganizational data sharing.
PRShare: a framework for privacy-preserving, interorganizational data sharing.PRShare: a framework for privacy-preserving, interorganizational data sharing.
PRShare: a framework for privacy-preserving, interorganizational data sharing.Lihi Idan
 
[Whitepaper] braintrust the decentralized_talent_network_9_2_21
[Whitepaper] braintrust the decentralized_talent_network_9_2_21[Whitepaper] braintrust the decentralized_talent_network_9_2_21
[Whitepaper] braintrust the decentralized_talent_network_9_2_21TranQuang734678
 
Patterns&Antipatternsof SOA
Patterns&Antipatternsof SOAPatterns&Antipatternsof SOA
Patterns&Antipatternsof SOAMohamed Samy
 
blockchain ppt for research puropse in the university
blockchain ppt for research puropse in the universityblockchain ppt for research puropse in the university
blockchain ppt for research puropse in the universitygugan7097
 
AWS&Deloitte Blockchain
AWS&Deloitte BlockchainAWS&Deloitte Blockchain
AWS&Deloitte BlockchainAlé Flores
 
Taking A Look At Web Services
Taking A Look At Web ServicesTaking A Look At Web Services
Taking A Look At Web ServicesStacey Cruz
 
iaetsd Shared authority based privacy preserving protocol
iaetsd Shared authority based privacy preserving protocoliaetsd Shared authority based privacy preserving protocol
iaetsd Shared authority based privacy preserving protocolIaetsd Iaetsd
 
Machine learning presentation in using pyhton
Machine learning presentation in using pyhtonMachine learning presentation in using pyhton
Machine learning presentation in using pyhtonmasukmia.com
 

Similar a Chain of responsibility (20)

Ladies Be Architects - Study Group III: OAuth 2.0 (Ep 1)
Ladies Be Architects - Study Group III: OAuth 2.0 (Ep 1)Ladies Be Architects - Study Group III: OAuth 2.0 (Ep 1)
Ladies Be Architects - Study Group III: OAuth 2.0 (Ep 1)
 
Agent basedqos
Agent basedqosAgent basedqos
Agent basedqos
 
Interview Questions For Microsoft Dynamics CRM
Interview Questions For Microsoft Dynamics CRMInterview Questions For Microsoft Dynamics CRM
Interview Questions For Microsoft Dynamics CRM
 
Test slideshow
Test slideshowTest slideshow
Test slideshow
 
Test slideshow
Test slideshowTest slideshow
Test slideshow
 
Test slideshow
Test slideshowTest slideshow
Test slideshow
 
Test slideshow
Test slideshowTest slideshow
Test slideshow
 
Web_based_content_management_system_using_crowdsourcing_technology
Web_based_content_management_system_using_crowdsourcing_technologyWeb_based_content_management_system_using_crowdsourcing_technology
Web_based_content_management_system_using_crowdsourcing_technology
 
DescriptionThis assignment will involve a proposal for the des.docx
DescriptionThis assignment will involve a proposal for the des.docxDescriptionThis assignment will involve a proposal for the des.docx
DescriptionThis assignment will involve a proposal for the des.docx
 
PRShare: a framework for privacy-preserving, interorganizational data sharing.
PRShare: a framework for privacy-preserving, interorganizational data sharing.PRShare: a framework for privacy-preserving, interorganizational data sharing.
PRShare: a framework for privacy-preserving, interorganizational data sharing.
 
GAP
GAPGAP
GAP
 
[Whitepaper] braintrust the decentralized_talent_network_9_2_21
[Whitepaper] braintrust the decentralized_talent_network_9_2_21[Whitepaper] braintrust the decentralized_talent_network_9_2_21
[Whitepaper] braintrust the decentralized_talent_network_9_2_21
 
Patterns&Antipatternsof SOA
Patterns&Antipatternsof SOAPatterns&Antipatternsof SOA
Patterns&Antipatternsof SOA
 
blockchain ppt for research puropse in the university
blockchain ppt for research puropse in the universityblockchain ppt for research puropse in the university
blockchain ppt for research puropse in the university
 
Agile user story mapping
Agile user story mappingAgile user story mapping
Agile user story mapping
 
AWS&Deloitte Blockchain
AWS&Deloitte BlockchainAWS&Deloitte Blockchain
AWS&Deloitte Blockchain
 
Taking A Look At Web Services
Taking A Look At Web ServicesTaking A Look At Web Services
Taking A Look At Web Services
 
Twet
TwetTwet
Twet
 
iaetsd Shared authority based privacy preserving protocol
iaetsd Shared authority based privacy preserving protocoliaetsd Shared authority based privacy preserving protocol
iaetsd Shared authority based privacy preserving protocol
 
Machine learning presentation in using pyhton
Machine learning presentation in using pyhtonMachine learning presentation in using pyhton
Machine learning presentation in using pyhton
 

Más de Shakil Ahmed

Más de Shakil Ahmed (16)

Algorithm
AlgorithmAlgorithm
Algorithm
 
B-tree & R-tree
B-tree & R-treeB-tree & R-tree
B-tree & R-tree
 
Advanced data structure
Advanced data structureAdvanced data structure
Advanced data structure
 
Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Facade pattern
Facade patternFacade pattern
Facade pattern
 
Composite pattern
Composite patternComposite pattern
Composite pattern
 
iOS 5
iOS 5iOS 5
iOS 5
 
Ios development
Ios developmentIos development
Ios development
 
Graph
GraphGraph
Graph
 
Lowest common ancestor
Lowest common ancestorLowest common ancestor
Lowest common ancestor
 
Segment tree
Segment treeSegment tree
Segment tree
 
Tree & bst
Tree & bstTree & bst
Tree & bst
 
Trie tree
Trie treeTrie tree
Trie tree
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Advanced Search Techniques
Advanced Search TechniquesAdvanced Search Techniques
Advanced Search Techniques
 

Último

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.pptxMaritesTamaniVerdade
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
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.pptxheathfieldcps1
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
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.christianmathematics
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
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.docxRamakrishna Reddy Bijjam
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
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...pradhanghanshyam7136
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
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.pdfAdmir Softic
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
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...Poonam Aher Patil
 

Último (20)

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
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
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
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
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.
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
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
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
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...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.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
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
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...
 

Chain of responsibility

  • 1. Design Pattern Chain of Responsibility A behavioral design pattern Mosfiqur Rahman Copyright © KAZ Software Limited
  • 2. Intent Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it. Copyright © KAZ Software Limited
  • 3. Motivation Consider a context-sensitive help facility for a graphical user interface. The user can obtain help information on any part of the interface just by clicking on it. The help that's provided depends on the part of the interface that's selected and its context; for example, a button widget in a dialog box might have different help information than a similar button in the main window. If no specific help information exists for that part of the interface, then the help system should display a more general help message about the immediate context—the dialog box as a whole, for example. Copyright © KAZ Software Limited
  • 4. Motivation Copyright © KAZ Software Limited
  • 5. Motivation The idea of this pattern is to decouple senders and receivers by giving multiple objects a chance to handle a request. The request gets passed along a chain of objects until one of them handles it. Let's assume the user clicks for help on a button widget marked "Print." The button is contained in an instance of PrintDialog, which knows the application object it belongs to (see preceding object diagram). The following interaction diagram illustrates how the help request gets forwarded along the chain: Copyright © KAZ Software Limited
  • 6. Motivation To forward the request along the chain, and to ensure receivers remain implicit, each object on the chain shares a common interface for handling requests and for accessing its successor on the chain. For example, the help system might define a HelpHandler class with a corresponding HandleHelp operation. HelpHandler can be the parent class for candidate object classes, or it can be defined as a mixin class. Then classes that want to handle help requests can make HelpHandler a parent. The Button, Dialog, and Application classes use HelpHandler operations to handle help requests. HelpHandler's HandleHelp operation forwards the request to the successor by default. Subclasses can override this operation to provide help under the right circumstances; otherwise they can use the default implementation to forward the request. Copyright © KAZ Software Limited
  • 7. Motivation In this case, neither aPrintButton nor aPrintDialog handles the request; it stops at anApplication, which can handle it or ignore it. The client that issued the request has no direct reference to the object that ultimately fulfills it. Copyright © KAZ Software Limited
  • 8. Applicability Use Chain of Responsibility when • more than one object may handle a request, and the handler isn't known a priori. The handler should be ascertained automatically. • you want to issue a request to one of several objects without specifying the receiver explicitly. • the set of objects that can handle a request should be specified dynamically. Copyright © KAZ Software Limited
  • 9. Structure A typical object structure might look like this: Copyright © KAZ Software Limited
  • 10. Participants • Handler (HelpHandler) o defines an interface for handling requests. o (optional) implements the successor link. • ConcreteHandler (PrintButton, PrintDialog) o handles requests it is responsible for. o can access its successor. o if the ConcreteHandler can handle the request, it does so; otherwise it forwards the request to its successor. • Client o initiates the request to a ConcreteHandler object on the chain. Copyright © KAZ Software Limited
  • 11. Collaborations When a client issues a request, the request propagates along the chain until a ConcreteHandler object takes responsibility for handling it. Copyright © KAZ Software Limited
  • 12. Consequences Chain of Responsibility has the following benefits and liabilities: 1. Reduced coupling. The pattern frees an object from knowing which other object handles a request. An object only has to know that a request will be handled "appropriately." Both the receiver and the sender have no explicit knowledge of each other, and an object in the chain doesn't have to know about the chain's structure. As a result, Chain of Responsibility can simplify object interconnections. Instead of objects maintaining references to all candidate receivers, they keep a single reference to their successor. 2. Added flexibility in assigning responsibilities to objects. Chain of Responsibility gives you added flexibility in distributing responsibilities among objects. You can add or change responsibilities for handling a request by adding to or otherwise changing the chain at run-time. You can combine this with subclassing to specialize handlers statically. Copyright © KAZ Software Limited
  • 13. Consequences 3. Receipt isn't guaranteed. Since a request has no explicit receiver, there's no guarantee it'll be handled—the request can fall off the end of the chain without ever being handled. A request can also go unhandled when the chain is not configured properly. Copyright © KAZ Software Limited
  • 14. Assignment In the banking system where cheque's for clearing is approved by the person but if the cheque amount is beyond certain limit, the approving responsibility moves the person higher in authority in the bank. Design the cheque approving system using the pattern in such a way that new limit can be easily introduced in the system. Its up to you to decide the number of default layers. Copyright © KAZ Software Limited