SlideShare a Scribd company logo
Chain of Responsibility
GoF Behavioral Design Pattern
Scenario: User Authentication
Using email/password

Using Local Network Login/pass

Authentication Module

Using Remote login/pass
Let’s code!
This mass is available at https://gist.github.com/hlegius/e1a721ebbc7de2a91fb1
Code Review
•
•
•
•
•
•
•

We got a Service class;
Skinny Controllers;
Meaningful (and cool) names;
No temp variable;
Short methods;
A lot of non-sense `ifs` statements;
(Very) Complicated logic. (WTF award!)
So, let’s go forward on that ?
WTF dude!?

Wrong design decision indicator!

This mass is available at https://gist.github.com/hlegius/e1a721ebbc7de2a91fb1
Chain of Responsibility
• Decouple client from receivers when you got
more than one object that can handle it;
• Giving you the chance to test each part
(sender and receivers) in isolated.
• Create one point of change if new Receiver
arrives.
• Added flexibility in assigning responsibilities to
objects;
• Boost your code readability like a boss.
This code is available at https://gist.github.com/hlegius/7188168
This code is available at https://gist.github.com/hlegius/7188168
This code is available at https://gist.github.com/hlegius/7188168
Chain of Responsibility
Bad Consequences
• More Lines of Code than first version;
• Complex if you have one or two fixes
receivers;
• Receipt is not guaranteed that will be
handled;
Known Uses
• Handle Events – Also known as “Event
Handler” or “Responder”
• ET++ used Chain of Responsibility to handle
Graphical Updates. (Took from GoF book)
Macro point of view - UML

Client

UserAuthenticator

Handler

Authenticator <abstract>

ConcreteHandler1

EmailAuthenticator

ConcreteHandler2

NetworkAuthenticator

ConcreteHandler3

PartnerAuthenticator
Don't get me wrong!

You can apply this with
PHP, Python, Ruby and so on.
Thank you!

http://programe.me

Reference: GoF book

More Related Content

What's hot

What's hot (20)

Being RDBMS Free -- Alternate Approaches to Data Persistence
Being RDBMS Free -- Alternate Approaches to Data PersistenceBeing RDBMS Free -- Alternate Approaches to Data Persistence
Being RDBMS Free -- Alternate Approaches to Data Persistence
 
Production - Designing for Testability
Production - Designing for TestabilityProduction - Designing for Testability
Production - Designing for Testability
 
Thunderstruck by serverless
Thunderstruck  by  serverlessThunderstruck  by  serverless
Thunderstruck by serverless
 
Azure functions
Azure functionsAzure functions
Azure functions
 
CloudFest 2018 Hackathon Project Results Presentation - CFHack18
CloudFest 2018 Hackathon Project Results Presentation - CFHack18CloudFest 2018 Hackathon Project Results Presentation - CFHack18
CloudFest 2018 Hackathon Project Results Presentation - CFHack18
 
When to use Serverless? When to use Kubernetes?
When to use Serverless? When to use Kubernetes?When to use Serverless? When to use Kubernetes?
When to use Serverless? When to use Kubernetes?
 
Building Autonomous Services
Building Autonomous ServicesBuilding Autonomous Services
Building Autonomous Services
 
Essential git for developers
Essential git for developersEssential git for developers
Essential git for developers
 
OSMC 2021 | Contributing to open source with the example of icinga (1)
OSMC 2021 | Contributing to open source with the example of icinga (1)OSMC 2021 | Contributing to open source with the example of icinga (1)
OSMC 2021 | Contributing to open source with the example of icinga (1)
 
We don't need consensus: All agreed?
We don't need consensus: All agreed?We don't need consensus: All agreed?
We don't need consensus: All agreed?
 
Serverless security - how to protect what you don't see?
Serverless security - how to protect what you don't see?Serverless security - how to protect what you don't see?
Serverless security - how to protect what you don't see?
 
The 7 deadly sins of micro services
The 7 deadly sins of micro servicesThe 7 deadly sins of micro services
The 7 deadly sins of micro services
 
Build a Chatbot in Ten Minutes - Dave Kerr - Serverless Summit
Build a Chatbot in Ten Minutes - Dave Kerr - Serverless SummitBuild a Chatbot in Ten Minutes - Dave Kerr - Serverless Summit
Build a Chatbot in Ten Minutes - Dave Kerr - Serverless Summit
 
Applying Roles and Profiles method to compliance code
Applying Roles and Profiles method to compliance codeApplying Roles and Profiles method to compliance code
Applying Roles and Profiles method to compliance code
 
Microservice Test Strategy (@Bonn Code Meetup)
Microservice Test Strategy (@Bonn Code Meetup)Microservice Test Strategy (@Bonn Code Meetup)
Microservice Test Strategy (@Bonn Code Meetup)
 
Testing Without a GUI Using TestComplete
 Testing Without a GUI Using TestComplete Testing Without a GUI Using TestComplete
Testing Without a GUI Using TestComplete
 
Continuous integration testing 2019 08
Continuous integration testing 2019 08Continuous integration testing 2019 08
Continuous integration testing 2019 08
 
Crafting high quality code
Crafting high quality code Crafting high quality code
Crafting high quality code
 
Forcelandia Salesforce CI
Forcelandia Salesforce CIForcelandia Salesforce CI
Forcelandia Salesforce CI
 
Microservices Testing at Scale
Microservices Testing at ScaleMicroservices Testing at Scale
Microservices Testing at Scale
 

Viewers also liked

Viewers also liked (16)

Bridge Pattern Derek Weeks
Bridge Pattern   Derek WeeksBridge Pattern   Derek Weeks
Bridge Pattern Derek Weeks
 
Bridge pattern
Bridge patternBridge pattern
Bridge 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
 
Chain of responsibility
Chain of responsibilityChain of responsibility
Chain of responsibility
 
Command Pattern
Command PatternCommand Pattern
Command Pattern
 
Command pattern
Command patternCommand pattern
Command pattern
 
Chain of Responsibility Pattern
Chain of Responsibility PatternChain of Responsibility Pattern
Chain of Responsibility Pattern
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
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
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Implementing the Adapter Design Pattern
Implementing the Adapter Design PatternImplementing the Adapter Design Pattern
Implementing the Adapter Design Pattern
 
Security and Integrity of Data
Security and Integrity of DataSecurity and Integrity of Data
Security and Integrity of Data
 

Similar to Chain of Responsibility Pattern

Kubernetes and container security
Kubernetes and container securityKubernetes and container security
Kubernetes and container security
Volodymyr Shynkar
 

Similar to Chain of Responsibility Pattern (20)

Secure Your Open Source Projects For Free
Secure Your Open Source Projects For FreeSecure Your Open Source Projects For Free
Secure Your Open Source Projects For Free
 
Continuous Delivery, Continuous Integration
Continuous Delivery, Continuous Integration Continuous Delivery, Continuous Integration
Continuous Delivery, Continuous Integration
 
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer ToolsDevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
 
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer ToolsDevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
 
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer ToolsDevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
 
Introduction to Blockchain and Hyperledger
Introduction to Blockchain and HyperledgerIntroduction to Blockchain and Hyperledger
Introduction to Blockchain and Hyperledger
 
Securing API data models
Securing API data modelsSecuring API data models
Securing API data models
 
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer ToolsDevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
 
Kubernetes and container security
Kubernetes and container securityKubernetes and container security
Kubernetes and container security
 
How do JavaScript frameworks impact the security of applications?
How do JavaScript frameworks impact the security of applications?How do JavaScript frameworks impact the security of applications?
How do JavaScript frameworks impact the security of applications?
 
DockerCon 15 Keynote - Day 2
DockerCon 15 Keynote - Day 2DockerCon 15 Keynote - Day 2
DockerCon 15 Keynote - Day 2
 
Kerberos, Token and Hadoop
Kerberos, Token and HadoopKerberos, Token and Hadoop
Kerberos, Token and Hadoop
 
Getting Ahead of Delivery Issues with Deep SDLC Analysis by Donald Belcham
Getting Ahead of Delivery Issues with Deep SDLC Analysis by Donald BelchamGetting Ahead of Delivery Issues with Deep SDLC Analysis by Donald Belcham
Getting Ahead of Delivery Issues with Deep SDLC Analysis by Donald Belcham
 
Getting Started with Serverless Architectures
Getting Started with Serverless ArchitecturesGetting Started with Serverless Architectures
Getting Started with Serverless Architectures
 
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer ToolsDevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
DevOps on AWS: Deep Dive on Continuous Delivery and the AWS Developer Tools
 
SHIFT LEFT WITH DEVSECOPS
SHIFT LEFT WITH DEVSECOPSSHIFT LEFT WITH DEVSECOPS
SHIFT LEFT WITH DEVSECOPS
 
Just kill it
Just kill itJust kill it
Just kill it
 
Protect Your Payloads: Modern Keying Techniques
Protect Your Payloads: Modern Keying TechniquesProtect Your Payloads: Modern Keying Techniques
Protect Your Payloads: Modern Keying Techniques
 
Blockchain in the Food Supply Chain (v2)
Blockchain in the Food Supply Chain (v2)Blockchain in the Food Supply Chain (v2)
Blockchain in the Food Supply Chain (v2)
 
Application Lifecycle Management
Application Lifecycle ManagementApplication Lifecycle Management
Application Lifecycle Management
 

More from Hélio Costa e Silva (6)

Annotation Sniffer Hotspots implementation
Annotation Sniffer Hotspots implementationAnnotation Sniffer Hotspots implementation
Annotation Sniffer Hotspots implementation
 
Lightning talk - Framework Architecture: Hotspots
Lightning talk  -  Framework Architecture: HotspotsLightning talk  -  Framework Architecture: Hotspots
Lightning talk - Framework Architecture: Hotspots
 
Vex 2009-2011
Vex 2009-2011Vex 2009-2011
Vex 2009-2011
 
Definir classe não é programar com orientação a objetos
Definir classe não é programar com orientação a objetosDefinir classe não é programar com orientação a objetos
Definir classe não é programar com orientação a objetos
 
WebVibe Barueri 2011 - "PHP por quê ?"
WebVibe Barueri 2011 - "PHP por quê ?"WebVibe Barueri 2011 - "PHP por quê ?"
WebVibe Barueri 2011 - "PHP por quê ?"
 
Test-Driven Development - Introdução
Test-Driven Development - IntroduçãoTest-Driven Development - Introdução
Test-Driven Development - Introdução
 

Recently uploaded

Listing Turkey - Sinpaş Queen Bomonti Katalog
Listing Turkey - Sinpaş Queen Bomonti KatalogListing Turkey - Sinpaş Queen Bomonti Katalog
Listing Turkey - Sinpaş Queen Bomonti Katalog
Listing Turkey
 
Killer Referans Bahcesehir Catalog Listing Turkey
Killer Referans Bahcesehir Catalog Listing TurkeyKiller Referans Bahcesehir Catalog Listing Turkey
Killer Referans Bahcesehir Catalog Listing Turkey
Listing Turkey
 
Torun Center Residences Istanbul - Listing Turkey
Torun Center Residences Istanbul - Listing TurkeyTorun Center Residences Istanbul - Listing Turkey
Torun Center Residences Istanbul - Listing Turkey
Listing Turkey
 

Recently uploaded (20)

What is BDA? Understanding the Bangalore Development Authority
What is BDA? Understanding the Bangalore Development AuthorityWhat is BDA? Understanding the Bangalore Development Authority
What is BDA? Understanding the Bangalore Development Authority
 
Listing Turkey - Sinpaş Queen Bomonti Katalog
Listing Turkey - Sinpaş Queen Bomonti KatalogListing Turkey - Sinpaş Queen Bomonti Katalog
Listing Turkey - Sinpaş Queen Bomonti Katalog
 
Kohinoor Dhanori Apartments Pune Brochure
Kohinoor Dhanori Apartments Pune BrochureKohinoor Dhanori Apartments Pune Brochure
Kohinoor Dhanori Apartments Pune Brochure
 
MC Heights-Best Construction Company in jhang
MC Heights-Best Construction Company in jhangMC Heights-Best Construction Company in jhang
MC Heights-Best Construction Company in jhang
 
Sefakoy Sinpas Boulevard Istanbul - Presentation
Sefakoy Sinpas Boulevard Istanbul - PresentationSefakoy Sinpas Boulevard Istanbul - Presentation
Sefakoy Sinpas Boulevard Istanbul - Presentation
 
Salarpuria Sattva Lakeridge Neopolis Hyderabad.pdf.pdf
Salarpuria Sattva Lakeridge Neopolis Hyderabad.pdf.pdfSalarpuria Sattva Lakeridge Neopolis Hyderabad.pdf.pdf
Salarpuria Sattva Lakeridge Neopolis Hyderabad.pdf.pdf
 
Elegant Evergreen Homes - Timeless Luxury in Yelahanka, Bangalore
Elegant Evergreen Homes - Timeless Luxury in Yelahanka, BangaloreElegant Evergreen Homes - Timeless Luxury in Yelahanka, Bangalore
Elegant Evergreen Homes - Timeless Luxury in Yelahanka, Bangalore
 
Vacant Land for Sale - 3612 Pioneer Road, Town of Middleton, WI
Vacant Land for Sale - 3612 Pioneer Road, Town of Middleton, WIVacant Land for Sale - 3612 Pioneer Road, Town of Middleton, WI
Vacant Land for Sale - 3612 Pioneer Road, Town of Middleton, WI
 
Redevelopment in Pune Challenges & Solutions (PPT).pdf
Redevelopment in Pune Challenges & Solutions (PPT).pdfRedevelopment in Pune Challenges & Solutions (PPT).pdf
Redevelopment in Pune Challenges & Solutions (PPT).pdf
 
Types and Sources of Mortgage Leads: What You Need to Know
Types and Sources of Mortgage Leads: What You Need to KnowTypes and Sources of Mortgage Leads: What You Need to Know
Types and Sources of Mortgage Leads: What You Need to Know
 
Sinpas Gokorman Presentation. - Listing Turkey
Sinpas Gokorman Presentation. - Listing TurkeySinpas Gokorman Presentation. - Listing Turkey
Sinpas Gokorman Presentation. - Listing Turkey
 
Killer Referans Bahcesehir Catalog Listing Turkey
Killer Referans Bahcesehir Catalog Listing TurkeyKiller Referans Bahcesehir Catalog Listing Turkey
Killer Referans Bahcesehir Catalog Listing Turkey
 
How to Scan Tenants in NYC - You Should Know!
How to Scan Tenants in NYC - You Should Know!How to Scan Tenants in NYC - You Should Know!
How to Scan Tenants in NYC - You Should Know!
 
Oeiras Tech City, Developed by RE Capital and REIG, Will Become Lisbon's Futu...
Oeiras Tech City, Developed by RE Capital and REIG, Will Become Lisbon's Futu...Oeiras Tech City, Developed by RE Capital and REIG, Will Become Lisbon's Futu...
Oeiras Tech City, Developed by RE Capital and REIG, Will Become Lisbon's Futu...
 
Torun Center Residences Istanbul - Listing Turkey
Torun Center Residences Istanbul - Listing TurkeyTorun Center Residences Istanbul - Listing Turkey
Torun Center Residences Istanbul - Listing Turkey
 
2BHK-3BHK NEW FLAT FOR SALE IN TUPUDANA,RANCHI.
2BHK-3BHK NEW FLAT FOR SALE IN TUPUDANA,RANCHI.2BHK-3BHK NEW FLAT FOR SALE IN TUPUDANA,RANCHI.
2BHK-3BHK NEW FLAT FOR SALE IN TUPUDANA,RANCHI.
 
Urbanrise Paradise on Earth - Unveiling Unprecedented Luxury in Exquisite Vil...
Urbanrise Paradise on Earth - Unveiling Unprecedented Luxury in Exquisite Vil...Urbanrise Paradise on Earth - Unveiling Unprecedented Luxury in Exquisite Vil...
Urbanrise Paradise on Earth - Unveiling Unprecedented Luxury in Exquisite Vil...
 
Shapoorji Pallonji Plots Jadhavgadh Fort Pune.pdf
Shapoorji Pallonji Plots Jadhavgadh Fort Pune.pdfShapoorji Pallonji Plots Jadhavgadh Fort Pune.pdf
Shapoorji Pallonji Plots Jadhavgadh Fort Pune.pdf
 
Avrupa Konutlari Yenimahalle - Listing Turkey
Avrupa Konutlari Yenimahalle - Listing TurkeyAvrupa Konutlari Yenimahalle - Listing Turkey
Avrupa Konutlari Yenimahalle - Listing Turkey
 
One FNG by Group 108 Sector 142 Noida Construction Update
One FNG by Group 108 Sector 142 Noida Construction UpdateOne FNG by Group 108 Sector 142 Noida Construction Update
One FNG by Group 108 Sector 142 Noida Construction Update
 

Chain of Responsibility Pattern

  • 1. Chain of Responsibility GoF Behavioral Design Pattern
  • 2. Scenario: User Authentication Using email/password Using Local Network Login/pass Authentication Module Using Remote login/pass
  • 4.
  • 5. This mass is available at https://gist.github.com/hlegius/e1a721ebbc7de2a91fb1
  • 6. Code Review • • • • • • • We got a Service class; Skinny Controllers; Meaningful (and cool) names; No temp variable; Short methods; A lot of non-sense `ifs` statements; (Very) Complicated logic. (WTF award!)
  • 7. So, let’s go forward on that ?
  • 8.
  • 9. WTF dude!? Wrong design decision indicator! This mass is available at https://gist.github.com/hlegius/e1a721ebbc7de2a91fb1
  • 10. Chain of Responsibility • Decouple client from receivers when you got more than one object that can handle it; • Giving you the chance to test each part (sender and receivers) in isolated. • Create one point of change if new Receiver arrives. • Added flexibility in assigning responsibilities to objects; • Boost your code readability like a boss.
  • 11. This code is available at https://gist.github.com/hlegius/7188168
  • 12.
  • 13. This code is available at https://gist.github.com/hlegius/7188168
  • 14. This code is available at https://gist.github.com/hlegius/7188168
  • 15. Chain of Responsibility Bad Consequences • More Lines of Code than first version; • Complex if you have one or two fixes receivers; • Receipt is not guaranteed that will be handled;
  • 16. Known Uses • Handle Events – Also known as “Event Handler” or “Responder” • ET++ used Chain of Responsibility to handle Graphical Updates. (Took from GoF book)
  • 17. Macro point of view - UML Client UserAuthenticator Handler Authenticator <abstract> ConcreteHandler1 EmailAuthenticator ConcreteHandler2 NetworkAuthenticator ConcreteHandler3 PartnerAuthenticator
  • 18. Don't get me wrong! You can apply this with PHP, Python, Ruby and so on.