The Chain of Responsibility Pattern Explained & Implemented | Behavioral Design Patterns | Geekific

  Рет қаралды 41,927

Geekific

Geekific

Күн бұрын

Support us on Patreon: / geekific
Discord Community: / discord
GitHub Repository: github.com/geekific-official/
In this video, we break down, define and implement in Java the Chain of Responsibility behavioral design pattern.
Timestamps:
00:00 Introduction
00:07 What is the Chain of Responsibility Pattern?
01:56 Chain of Responsibility Pattern Class Diagram
03:08 Chain of Responsibility Implementation
06:46 Recap
07:26 Thanks for Watching!
If you found this video helpful, check other Geekific uploads:
- Introduction to Design Patterns: • What are Design Patter...
- The Factory Method Pattern Explained and Implemented in Java: • The Factory Method Pat...
- The Abstract Factory Pattern Explained and Implemented in Java: • The Abstract Factory P...
- The Singleton Pattern Explained and Implemented in Java: • The Singleton Pattern ...
- Object-Oriented Programming Fundamentals: • What is Object-Oriente...
- SOLID Principles and Best Practices: • SOLID Design Principle...
#Geekific #DesignPatterns #ChainOfResponsibilityPattern #BehavioralPatterns

Пікірлер: 28
@geekific
@geekific 2 жыл бұрын
Thanks to @Michal Dudek in the comments below, at around 6:40 the code on the main class should be the below (it is updated on GitHub): Handler handler = new UserExistsHandler(database); handler.setNextHandler(new ValidPasswordHandler(database)) .setNextHandler(new RoleCheckHandler()); AuthService service = new AuthService(handler);
@danielfernandes1
@danielfernandes1 Жыл бұрын
Hi! I have a question. At around 6:40 shouldn't it instead be Handler handler = new UserExistsHandler(database); handler.setNextHandler( new ValidPasswordHandler(database) .setNextHandler(new RoleCheckHandler()) ); After all we're defining a next handler to the UserExistsHandler, which is ValidPasswordHandler, but then we have to set a next Handler to ValidPasswordHandler, not UserExistsHandler. The way your code is, we're just overriding the value of the nextHandler on UserExistsHandler is it not?
@geekific
@geekific Жыл бұрын
@@danielfernandes1 4:35 ;)
@Stikmanas
@Stikmanas 6 ай бұрын
you are the greatest man, made a module in university 10x easier, I love you man
@elyakimlev
@elyakimlev 2 жыл бұрын
Thanks for these clear explanations. I'm actually a programmer several years now (mobile game industry), but where I have been working, we haven't had any strict rules so everybody just implemented things as they saw fit. Now that I'm thinking of moving to another company, I realize I lack some fundamental programming skills and your lessons are quite helpful. Clearer than other tutorials I've seen. Thanks!
@geekific
@geekific 2 жыл бұрын
I am so glad I can be of help! Good luck with your new role :)
@rvscootin3457
@rvscootin3457 3 ай бұрын
It reminds me of the old Linked List in C++ where you had a serf referencing pointer [Node] that points to the Next->Node.
@waeljawadi3253
@waeljawadi3253 Жыл бұрын
Thanks, for the effort creating those well explained videos and for the well choosen examples
@sperpflerperberg8147
@sperpflerperberg8147 Жыл бұрын
These videos are fantastic!
@lpandp90
@lpandp90 4 ай бұрын
Great video
@mikooovsky
@mikooovsky 2 жыл бұрын
Great tutorial! But I think there is a little mistake in the main method in 6:40. Since the 'setNextHandler' method returns the handler that we passed in, so when creating an instance of the AuthService, we pass the last handler from the entire Chain (in this case RoleCheckHandler) to its constructor, so the entire authentication flow doesn't work properly, because it executes only RoleCheckHandler. I guess we should assign UserExistsHandler to the variable 'handler'. Then using this variable, we should set the next handlers using the 'setNextHandler' method, and pass the 'handler' variable to the AuthService constructor. Am I correct?
@geekific
@geekific 2 жыл бұрын
Very very nice! Well done bro! The code is updated on GitHub, however can't remember what happened at the time and why it figures this way in the video! xD Thanks man :)
@PecPur
@PecPur 2 жыл бұрын
I came here to say this.
@joostvandam8624
@joostvandam8624 3 ай бұрын
I found the same issue, therefore I just declared the Handler at 1 line and chained the other handlers to it at a new one.
@bob_mikhail
@bob_mikhail 3 ай бұрын
How do you insert, remove or reorder handlers dynamically? Each handler only has a reference to the next one
@wesamalkhteeb4474
@wesamalkhteeb4474 Жыл бұрын
thank you😍😍
@imad.alilat
@imad.alilat Жыл бұрын
Thank you for the this amazing videos ! you are the best Sir !
@geekific
@geekific Жыл бұрын
My pleasure! Glad I can be of help :)
@__ShamimaAkterShimu
@__ShamimaAkterShimu Жыл бұрын
Why chain of responsibility is a behaviour design pattern? Plz ans me.
@geekific
@geekific Жыл бұрын
Behavioral Patterns are concerned with communication and assignment of responsibilities between objects as the program is running, and the CoR is all about that! It creates several handlers each having a specific responsibility, and the behavior of each handler (execute, pass to next or stop) is determined by the request passed-in by the user at runtime. Hope this answers it!
@antwanwimberly1729
@antwanwimberly1729 8 ай бұрын
Hames Gosling
@prolamaamvs6952
@prolamaamvs6952 Жыл бұрын
i am sorry but i try to implement your code , i understood everything but this setNextHandler is not right becouse you will always set the last handler in witch case you will have only one handler
@geekific
@geekific Жыл бұрын
Yes, there is a pinned comment for it, and it is updated on GitHub :)
@prolamaamvs6952
@prolamaamvs6952 Жыл бұрын
@@geekific sorry man , didnt thank you a lot for this tutorial 😁
@siddhanthsridhar4742
@siddhanthsridhar4742 2 ай бұрын
pesu students thumbs up if here
@siddhanthsridhar4742
@siddhanthsridhar4742 2 ай бұрын
# 1 night before isa
@cparks1000000
@cparks1000000 Жыл бұрын
I realize that this is outside the scope of the video; however, it's poor security protocol to tell a (possibly malicious) user weather or not the username exists. This gives the adversary extra information to use in the attack. If you send, "wrong password" the adversary now knows that the username exists and they should try more passwords. If you just send, "Invalid login information," the adversary doesn't know if the username is wrong or the password is wrong. This is particularly an issue when people reuse passwords and/or usernames (or variants thereof).
@geekific
@geekific Жыл бұрын
In this video we are trying to focus on explaining and understanding the pattern in question, but yes you are right :)
Heartwarming moment as priest rescues ceremony with kindness #shorts
00:33
Fabiosa Best Lifehacks
Рет қаралды 8 МЛН
路飞被小孩吓到了#海贼王#路飞
00:41
路飞与唐舞桐
Рет қаралды 71 МЛН
Мы никогда не были так напуганы!
00:15
Аришнев
Рет қаралды 6 МЛН
Chain of Responsibility Design Pattern in detail | Interview Question
9:49
5 Design Patterns That Are ACTUALLY Used By Developers
9:27
Alex Hyett
Рет қаралды 212 М.
Chain of Responsibility to the Rescue!
9:15
Zoran Horvat
Рет қаралды 10 М.
10 Design Patterns Explained in 10 Minutes
11:04
Fireship
Рет қаралды 2,2 МЛН
Object-Oriented Programming is Embarrassing: 4 Short Examples
28:03
The Smart Way of Using the Decorator Pattern in C#
12:37
Nick Chapsas
Рет қаралды 66 М.
Heartwarming moment as priest rescues ceremony with kindness #shorts
00:33
Fabiosa Best Lifehacks
Рет қаралды 8 МЛН