SlideShare a Scribd company logo
1 of 13
Chain of Responsibility
From Definition to Implementation
Mudasir Qazi - mudasirqazi00@gmail.com 116-Dec-14
Contents / Agenda
• Definition
• Advantages and Usage
• UML Diagram
• Sequence Diagram
• Daily life Examples
• Implementation – Scenario UML
• Implementation – Steps 1 to 4
• Results
Mudasir Qazi - mudasirqazi00@gmail.com 216-Dec-14
Definition
1. Avoid coupling the sender of a request to its receiver by giving
multiple objects a chance to handle the request.
2. We can say that normally each receiver contains reference of another
receiver. If one object cannot handle the request then it passes the
same to the next receiver and so on.
3. Chain the receiving objects and pass the request along the chain until
an object handles it.
• It comes under the “Behavioral Design Patterns”.
Mudasir Qazi - mudasirqazi00@gmail.com 316-Dec-14
Advantages and Usage
• Advantages:
1. It reduces the coupling.
2. It adds flexibility while assigning the responsibilities to objects.
3. It allows a set of classes to act as one, events produced in one class can be sent
to other handler classes with the help of composition.
• Usage:
1. When more than one object can handle a request and the handler is unknown.
2. When the group of objects that can handle the request must be specified in
dynamic way.
Mudasir Qazi - mudasirqazi00@gmail.com 416-Dec-14
UML Diagram
Client’s Request comes to
the (abstract) handler and
it decides that which of the
(concrete) sub handlers will
actually full fil the request.
If request is not completed
by first assigned sub
handler then it returns it to
the base handler and it
decides which of the sub
handlers is now feasible for
task.
Mudasir Qazi - mudasirqazi00@gmail.com 516-Dec-14
UML – Sequence Diagram
Mudasir Qazi - mudasirqazi00@gmail.com 616-Dec-14
Examples
1. Leave Application Example:
Lets say we have an organization where Team members when apply for leave, the request goes to
the Team Leader. Team leader can approve all the leave request of less than 10 days. If the leave
request is of more than 10 days then the request will be passed on to the Project Leader. Project
leader is able to approve leaves of up to 20 days. If the leave is applied for more than 20 days then
this requests will be passed to the HR. HR can approve up to 30 days of leave. If the leave is of
more than 30 days then the leave application cannot be approved by the system and it needs a
manual process for approval.
2. Loan Approval Example:
In a bank where the approval route for mortgage applications are from the bank manager to the
director then to the vice president, where the approval limits are:
Manager – 0 to 100k
Director – 100k to 250k
Vice President – anything above 250k
We will pass the request to the manager until the application is processed.
Mudasir Qazi - mudasirqazi00@gmail.com 716-Dec-14
Implementation – Loan Approval Example
• We are going to implement loan approval example like discussed above. Following is its UML Diagram.
Approving Limits:
Manager – 0 to 100k
Director – 100k to 250k
Vice President – anything above 250k
Mudasir Qazi - mudasirqazi00@gmail.com 816-Dec-14
Step 1 : Loan Class
Our Loan class contains an integer to hold loan
amount, a getter property and a constructor
working as a setter method.
Mudasir Qazi - mudasirqazi00@gmail.com 916-Dec-14
Step 2 : Main Handler (abstract)
This class is going to act as main request handler, every request
form client will be accepted by this and then this will pass request
to its subclasses.
Mudasir Qazi - mudasirqazi00@gmail.com 1016-Dec-14
Step 3 : Concrete Classes
Note: All these classes are inherited form our
LoanApprover abstract class. And implements
the ApproveLoan method with respect to
their expectations.
Mudasir Qazi - mudasirqazi00@gmail.com 1116-Dec-14
Step 4 : Testing
We created three object to test with different
amounts. Then we have to tell the hierarchy
by SetNextApprover method.
Mudasir Qazi - mudasirqazi00@gmail.com 1216-Dec-14
Step 5 : Results
• Here are results as we expected.
Mudasir Qazi - mudasirqazi00@gmail.com 1316-Dec-14

More Related Content

What's hot

Why Domain-Driven Design and Reactive Programming?
Why Domain-Driven Design and Reactive Programming?Why Domain-Driven Design and Reactive Programming?
Why Domain-Driven Design and Reactive Programming?
VMware Tanzu
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with code
kamal kotecha
 
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Meenakshi Devi
 

What's hot (20)

Lecture04- Use Case Diagrams
Lecture04- Use Case DiagramsLecture04- Use Case Diagrams
Lecture04- Use Case Diagrams
 
Proxy pattern
Proxy patternProxy pattern
Proxy pattern
 
Pros & Cons of Microservices Architecture
Pros & Cons of Microservices ArchitecturePros & Cons of Microservices Architecture
Pros & Cons of Microservices Architecture
 
Composite pattern
Composite patternComposite pattern
Composite pattern
 
Command pattern
Command patternCommand pattern
Command pattern
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design Pattern
 
Publish Subscribe pattern - Design Patterns
Publish Subscribe pattern - Design PatternsPublish Subscribe pattern - Design Patterns
Publish Subscribe pattern - Design Patterns
 
Why Domain-Driven Design and Reactive Programming?
Why Domain-Driven Design and Reactive Programming?Why Domain-Driven Design and Reactive Programming?
Why Domain-Driven Design and Reactive Programming?
 
Struts2
Struts2Struts2
Struts2
 
Flyweight pattern
Flyweight patternFlyweight pattern
Flyweight pattern
 
Event Sourcing - Greg Young
Event Sourcing - Greg YoungEvent Sourcing - Greg Young
Event Sourcing - Greg Young
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with code
 
Introduction to object-oriented analysis and design (OOA/D)
Introduction to object-oriented analysis and design (OOA/D)Introduction to object-oriented analysis and design (OOA/D)
Introduction to object-oriented analysis and design (OOA/D)
 
Software Engineering - chp4- design patterns
Software Engineering - chp4- design patternsSoftware Engineering - chp4- design patterns
Software Engineering - chp4- design patterns
 
React & GraphQL
React & GraphQLReact & GraphQL
React & GraphQL
 
Microservice Architecture using Spring Boot with React & Redux
Microservice Architecture using Spring Boot with React & ReduxMicroservice Architecture using Spring Boot with React & Redux
Microservice Architecture using Spring Boot with React & Redux
 
Software Engineering - chp5- software architecture
Software Engineering - chp5- software architectureSoftware Engineering - chp5- software architecture
Software Engineering - chp5- software architecture
 
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
Mapping Problem Domain Objects to Object-Persistence Formats(OOAD)
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
 
Types of UML diagrams
Types of UML diagramsTypes of UML diagrams
Types of UML diagrams
 

Similar to Design Pattern - Chain of Responsibility

3wks Introduction Pack
3wks Introduction Pack3wks Introduction Pack
3wks Introduction Pack
Alex Freeman
 

Similar to Design Pattern - Chain of Responsibility (20)

Design pattern - Facade Pattern
Design pattern - Facade PatternDesign pattern - Facade Pattern
Design pattern - Facade Pattern
 
JACKY KUMAR
JACKY KUMARJACKY KUMAR
JACKY KUMAR
 
Project Plan And Estimation
Project Plan And EstimationProject Plan And Estimation
Project Plan And Estimation
 
Mohamed .doc
Mohamed .docMohamed .doc
Mohamed .doc
 
PSMA - Gestione Missioni DIAG
PSMA - Gestione Missioni DIAGPSMA - Gestione Missioni DIAG
PSMA - Gestione Missioni DIAG
 
Assignment Help Moodle Monkey
Assignment Help Moodle Monkey Assignment Help Moodle Monkey
Assignment Help Moodle Monkey
 
Non functional performance requirements v2.2
Non functional performance requirements v2.2Non functional performance requirements v2.2
Non functional performance requirements v2.2
 
OOP - Understanding association, aggregation, composition and dependency
OOP - Understanding association, aggregation, composition and dependencyOOP - Understanding association, aggregation, composition and dependency
OOP - Understanding association, aggregation, composition and dependency
 
Development Framework method (Agile project analysis)
Development Framework method (Agile project analysis)Development Framework method (Agile project analysis)
Development Framework method (Agile project analysis)
 
Groom Auto Project
Groom Auto ProjectGroom Auto Project
Groom Auto Project
 
Toronto ACE Sept 2022.pptx
Toronto ACE Sept 2022.pptxToronto ACE Sept 2022.pptx
Toronto ACE Sept 2022.pptx
 
Алексей Денисюк "When Agile doesn't work. Tips and Tricks"
Алексей Денисюк "When Agile doesn't work. Tips and Tricks"Алексей Денисюк "When Agile doesn't work. Tips and Tricks"
Алексей Денисюк "When Agile doesn't work. Tips and Tricks"
 
Agile Development with Agile Contract
Agile Development with Agile ContractAgile Development with Agile Contract
Agile Development with Agile Contract
 
Cognitive 544 pa_art
Cognitive 544 pa_artCognitive 544 pa_art
Cognitive 544 pa_art
 
MWLUG 2017: Best Practices before, during, and after moving to IBM SmartCloud...
MWLUG 2017: Best Practices before, during, and after moving to IBM SmartCloud...MWLUG 2017: Best Practices before, during, and after moving to IBM SmartCloud...
MWLUG 2017: Best Practices before, during, and after moving to IBM SmartCloud...
 
Agile Guru - Agile Culture, Management Best Practices and App Dev Practices
Agile Guru - Agile Culture, Management Best Practices and App Dev Practices Agile Guru - Agile Culture, Management Best Practices and App Dev Practices
Agile Guru - Agile Culture, Management Best Practices and App Dev Practices
 
Project Administration Proposal Template PowerPoint Presentation Slides
Project Administration Proposal Template PowerPoint Presentation SlidesProject Administration Proposal Template PowerPoint Presentation Slides
Project Administration Proposal Template PowerPoint Presentation Slides
 
3wks Introduction Pack
3wks Introduction Pack3wks Introduction Pack
3wks Introduction Pack
 
Lalit Resume 12-03-15
Lalit Resume 12-03-15Lalit Resume 12-03-15
Lalit Resume 12-03-15
 
Key Terms in MS Project.pptx
Key Terms in MS Project.pptxKey Terms in MS Project.pptx
Key Terms in MS Project.pptx
 

More from Mudasir Qazi

More from Mudasir Qazi (12)

Design Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternDesign Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory Pattern
 
Database - SQL Joins
Database - SQL JoinsDatabase - SQL Joins
Database - SQL Joins
 
Database - Normalization
Database - NormalizationDatabase - Normalization
Database - Normalization
 
Database - Entity Relationship Diagram (ERD)
Database - Entity Relationship Diagram (ERD)Database - Entity Relationship Diagram (ERD)
Database - Entity Relationship Diagram (ERD)
 
OOP - Polymorphism
OOP - PolymorphismOOP - Polymorphism
OOP - Polymorphism
 
OOP - Java is pass-by-value
OOP - Java is pass-by-valueOOP - Java is pass-by-value
OOP - Java is pass-by-value
 
OOP - Benefits and advantages of OOP
OOP - Benefits and advantages of OOPOOP - Benefits and advantages of OOP
OOP - Benefits and advantages of OOP
 
Design Pattern - Singleton Pattern
Design Pattern - Singleton PatternDesign Pattern - Singleton Pattern
Design Pattern - Singleton Pattern
 
Design Pattern - Observer Pattern
Design Pattern - Observer PatternDesign Pattern - Observer Pattern
Design Pattern - Observer Pattern
 
Design Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMDesign Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVM
 
Design Pattern - Introduction
Design Pattern - IntroductionDesign Pattern - Introduction
Design Pattern - Introduction
 
Design Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternDesign Pattern - Factory Method Pattern
Design Pattern - Factory Method Pattern
 

Recently uploaded

Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Dr.Costas Sachpazis
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 

Recently uploaded (20)

data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 

Design Pattern - Chain of Responsibility

  • 1. Chain of Responsibility From Definition to Implementation Mudasir Qazi - mudasirqazi00@gmail.com 116-Dec-14
  • 2. Contents / Agenda • Definition • Advantages and Usage • UML Diagram • Sequence Diagram • Daily life Examples • Implementation – Scenario UML • Implementation – Steps 1 to 4 • Results Mudasir Qazi - mudasirqazi00@gmail.com 216-Dec-14
  • 3. Definition 1. Avoid coupling the sender of a request to its receiver by giving multiple objects a chance to handle the request. 2. We can say that normally each receiver contains reference of another receiver. If one object cannot handle the request then it passes the same to the next receiver and so on. 3. Chain the receiving objects and pass the request along the chain until an object handles it. • It comes under the “Behavioral Design Patterns”. Mudasir Qazi - mudasirqazi00@gmail.com 316-Dec-14
  • 4. Advantages and Usage • Advantages: 1. It reduces the coupling. 2. It adds flexibility while assigning the responsibilities to objects. 3. It allows a set of classes to act as one, events produced in one class can be sent to other handler classes with the help of composition. • Usage: 1. When more than one object can handle a request and the handler is unknown. 2. When the group of objects that can handle the request must be specified in dynamic way. Mudasir Qazi - mudasirqazi00@gmail.com 416-Dec-14
  • 5. UML Diagram Client’s Request comes to the (abstract) handler and it decides that which of the (concrete) sub handlers will actually full fil the request. If request is not completed by first assigned sub handler then it returns it to the base handler and it decides which of the sub handlers is now feasible for task. Mudasir Qazi - mudasirqazi00@gmail.com 516-Dec-14
  • 6. UML – Sequence Diagram Mudasir Qazi - mudasirqazi00@gmail.com 616-Dec-14
  • 7. Examples 1. Leave Application Example: Lets say we have an organization where Team members when apply for leave, the request goes to the Team Leader. Team leader can approve all the leave request of less than 10 days. If the leave request is of more than 10 days then the request will be passed on to the Project Leader. Project leader is able to approve leaves of up to 20 days. If the leave is applied for more than 20 days then this requests will be passed to the HR. HR can approve up to 30 days of leave. If the leave is of more than 30 days then the leave application cannot be approved by the system and it needs a manual process for approval. 2. Loan Approval Example: In a bank where the approval route for mortgage applications are from the bank manager to the director then to the vice president, where the approval limits are: Manager – 0 to 100k Director – 100k to 250k Vice President – anything above 250k We will pass the request to the manager until the application is processed. Mudasir Qazi - mudasirqazi00@gmail.com 716-Dec-14
  • 8. Implementation – Loan Approval Example • We are going to implement loan approval example like discussed above. Following is its UML Diagram. Approving Limits: Manager – 0 to 100k Director – 100k to 250k Vice President – anything above 250k Mudasir Qazi - mudasirqazi00@gmail.com 816-Dec-14
  • 9. Step 1 : Loan Class Our Loan class contains an integer to hold loan amount, a getter property and a constructor working as a setter method. Mudasir Qazi - mudasirqazi00@gmail.com 916-Dec-14
  • 10. Step 2 : Main Handler (abstract) This class is going to act as main request handler, every request form client will be accepted by this and then this will pass request to its subclasses. Mudasir Qazi - mudasirqazi00@gmail.com 1016-Dec-14
  • 11. Step 3 : Concrete Classes Note: All these classes are inherited form our LoanApprover abstract class. And implements the ApproveLoan method with respect to their expectations. Mudasir Qazi - mudasirqazi00@gmail.com 1116-Dec-14
  • 12. Step 4 : Testing We created three object to test with different amounts. Then we have to tell the hierarchy by SetNextApprover method. Mudasir Qazi - mudasirqazi00@gmail.com 1216-Dec-14
  • 13. Step 5 : Results • Here are results as we expected. Mudasir Qazi - mudasirqazi00@gmail.com 1316-Dec-14