Chain of Responsibility Design Pattern

preview_player
Показать описание

Welcome to my Chain of Responsibility Design Pattern Tutorial! Wow, that was a mouthful!

This pattern has a group of objects that are expected to between them be able to solve a problem. If the first Object can't solve it, it passes the data to the next Object in the chain. In this tutorial, I'll use it to make the right calculations based off of a String request. While that is pretty simple the capabilities of this pattern are endless.
Рекомендации по теме
Комментарии
Автор

Hours of searching for a decent example and Sir Derek Banas did it 7+ year ago. No one can top you sir, you are the best.

valkon_
Автор

may you never stop doing what you do. it helped me a lot.
off-topic: if my android app is going to be a success, you will be the one deserving a lot of thanks.

DragosMarcean
Автор

You're very welcome. I found the GOF book is bad at explaining the patterns in simple ways some times, so I worked hard to make it easier. I'm glad you found it useful. Soon I'll cover refactoring so that it is easier to figure out when to use the patterns

derekbanas
Автор

You would use this pattern and most of the others when the system becomes very complex. You are correct that this specific situation wouldn't require the pattern. I make a trade off in these tutorials. I simplify them so they can be easily understood, but to do that I can't apply them in complex systems, which is where they are required. I think you already figured out that flaw though. I hope that makes sense

derekbanas
Автор

You're very welcome :) I've been playing with some SEO stuff. My Google+ pic now shows up in search results which is driving some traffic. That is why my name changed. I just did everything the way I did to avoid confusing people while focusing on the pattern. You guys don't see most of the confused questions because a lot of people direct message me rather than comment

derekbanas
Автор

This is fantastic. I have been trying to learn the Gang Of Four design patterns for so many years it's embarrassing to even think of the size of that number. It is so hard to get the design patterns to sink deeply into the mind so that they feel intuitive and "obvious". Your "Chain of Responsibility" video did the trick for me. Finally, I feel like I understand this pattern. Thank you!

robertgloverjr
Автор

It allows you to simulate an organic process of solving a problem or passing the problem to another object to solve. I love it when I can simulate life in programming and this pattern achieves that.

derekbanas
Автор

Thank you :) the strategy pattern is used when you have a pretty definite short list of solutions. The cor pattern is a more liquid pattern that can handle numerous deviations from the norm. That makes the cor somewhat confusing especially for inexperienced programmers. You should only use the cor if you have to because understandable code is always the goal. Strategy is just easier to understand and normally gets the job done

derekbanas
Автор

Thank you :) I'll be covering J2EE Patterns after I cover J2EE. There is so much to cover it is hard to figure out what to do next. I'm going to finish the GOF patterns and then cover UML 2. Then I'll cover object oriented analysis and refactoring. Everyone has been asking for game tutorials, so I was then going to cover that plus all the math involved. Then J2EE, Hibernate, Spring, etc.

derekbanas
Автор

Thank you :) I do my best to follow the KISS principle. I will revisit Design Patterns when I start with C++. My C tutorials start next week and they will be followed by C++. I'm going to start mixing in new tutorials along with the Android tutorials which will last for the rest of the year

derekbanas
Автор

Derek, It's awesome that posted how to do the chain of responsibility pattern. But if your goal was to teach people about the pattern I think more time should have been spent on explaining why someone should use the pattern. You jumped into the implementation far too quickly, I am 2:00 minutes into the video I still have no idea why or when I would use the pattern. This should be the first thing mentioned. Why is the pattern important? What problem does it solve? What are some concrete cases where it might be used? How is it better than say "using simple case statements". You're a clear speaker, I like how you used UML to help explain the pattern (A lot of people don't even do that), but the explanation needs to include the motivations for the pattern.

chriskerley
Автор

Clear, detailed, no more confusion with Design Pattern, it's just awesome.
Please keep up the great work...

manish
Автор

Cor is used when it makes sense for object creation to occur in a series of steps. Does that help

derekbanas
Автор

Thank your Derek ..i guess the biggest compliment for your hard work is " The best videos on Design pattern on you tube "

pawanshrivastava
Автор

Thank you :) I was wondering if I should cover algorithms or not? I definitely could do that. I may skip refactoring for now and jump into algorithms instead. Thanks for the request

derekbanas
Автор

Thank you for the kind message :) You may also like the refactoring tutorial. I talk a great deal about patterns there as well. You're are always very welcome

derekbanas
Автор

Thank you very much :) If you like complicated niche tutorials on high level programming you are in the right place. Thanks for giving my videos a try

derekbanas
Автор

That is kind of a trade off. Optimized code is normally less understandable. Another thing that isn't often thought about is that the compiler often does its best to optimize code. I normally prefer to use a language like c++ when speed is very important as well.

derekbanas
Автор

Good video, thanks for explaining this pattern.
Just one thing, it's bad way to compare String with '==', you should call the equals method. It's working in this only because you used the same literal "add" or "sub" ... so the JVM creates only one object with that value.

fabioesposito
Автор

It normally is a bad idea to change the structure of your code to fit a pattern. Aim to write understandable code above all else. I found personally that one of the most important things to learn about design patterns is when not to use them

derekbanas