SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

Chain of Responsibility Pattern
Chain of Responsibility PatternChain of Responsibility Pattern
Chain of Responsibility PatternHüseyin Ergin
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design patternMindfire Solutions
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patternsAmit Kabra
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan GoleChetan Gole
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General IntroductionAsma CHERIF
 
Design Patterns
Design PatternsDesign Patterns
Design Patternssoms_1
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Elizabeth alexander
 
Sequence diagram
Sequence diagramSequence diagram
Sequence diagramRahul Pola
 
Iterator Design Pattern
Iterator Design PatternIterator Design Pattern
Iterator Design PatternVarun Arora
 
Gof design pattern
Gof design patternGof design pattern
Gof design patternnaveen kumar
 
PATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design PatternsPATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design PatternsMichael Heron
 

Tendances (20)

Builder pattern
Builder patternBuilder pattern
Builder pattern
 
Prototype pattern
Prototype patternPrototype pattern
Prototype pattern
 
Chain of Responsibility Pattern
Chain of Responsibility PatternChain of Responsibility Pattern
Chain of Responsibility Pattern
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patterns
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan Gole
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Prototype Design Pattern
Prototype Design PatternPrototype Design Pattern
Prototype Design Pattern
 
Java rmi
Java rmiJava rmi
Java rmi
 
Timer control
Timer controlTimer control
Timer control
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
 
Proxy pattern
Proxy patternProxy pattern
Proxy pattern
 
Sequence diagram
Sequence diagramSequence diagram
Sequence diagram
 
Iterator Design Pattern
Iterator Design PatternIterator Design Pattern
Iterator Design Pattern
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
 
Adapter pattern
Adapter patternAdapter pattern
Adapter pattern
 
PATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design PatternsPATTERNS04 - Structural Design Patterns
PATTERNS04 - Structural Design Patterns
 

En vedette

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
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design PatternShahriar Hyder
 
Descriptive statistics
Descriptive statisticsDescriptive statistics
Descriptive statisticsRajesh Gunesh
 

En vedette (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
Bridge patternBridge pattern
Bridge 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
 
Command pattern
Command patternCommand pattern
Command pattern
 
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
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design Pattern
 
Descriptive statistics
Descriptive statisticsDescriptive statistics
Descriptive statistics
 

Similaire à Chain of Responsibility Design Pattern for Bank Cheque Approval System

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
 

Similaire à Chain of Responsibility Design Pattern for Bank Cheque Approval System (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
 

Plus de Shakil Ahmed

Plus 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
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Flyweight pattern
Flyweight patternFlyweight pattern
Flyweight 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
 

Dernier

Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 

Dernier (20)

OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 

Chain of Responsibility Design Pattern for Bank Cheque Approval System

  • 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