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.
@derekbanas5 жыл бұрын
Thank you for the nice compliment :)
@derekbanas12 жыл бұрын
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
@DragosMarcean10 жыл бұрын
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.
@derekbanas10 жыл бұрын
Thank you for the nice compliment :) I plan on making tutorials for as long as I can.
@AmitKumarGrrowingSlow7 жыл бұрын
LOL, you are a humble man
@derekbanas11 жыл бұрын
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
@robertgloverjr12 жыл бұрын
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!
@derekbanas11 жыл бұрын
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
@srikajol16 күн бұрын
As much i love programming, i consider myself a slow learner and examples as this helps understand things easier. Thanks for a great content. Anybody can teach, but not everyone is a teacher.
@derekbanas11 жыл бұрын
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.
@derekbanas12 жыл бұрын
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
@derekbanas12 жыл бұрын
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.
@derekbanas12 жыл бұрын
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
@rabeebibrat18055 жыл бұрын
A good example is a king giving an order to the minister. The minister takes some major steps, while give additional orders to the generals. The generals take some strategic military steps in their respective areas. Besides they also employ the soldiers and archers with different sets of duties. The above example can be accomplished in COR, but not in strategy pattern.
@pawanshrivastava740511 жыл бұрын
Thank your Derek ..i guess the biggest compliment for your hard work is " The best videos on Design pattern on you tube "
@derekbanas11 жыл бұрын
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
@manish4365 жыл бұрын
Clear, detailed, no more confusion with Design Pattern, it's just awesome. Please keep up the great work...
@derekbanas5 жыл бұрын
Thank you very much :)
@derekbanas12 жыл бұрын
Cor is used when it makes sense for object creation to occur in a series of steps. Does that help
@chriskerley15087 жыл бұрын
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.
@derekbanas7 жыл бұрын
Sorry for not covering that. At the time I created this to make the GOF book easy to understand and I assumed that everyone looking at this would also be reading everything in the GOF book. In hindsight I should have covered that.
@Noble_17766 жыл бұрын
If someone is reading this and wondering why you would want to do this the main reason I can think of is this... Essentially what you are building here is a switch statement BUT instead of having a hard coded switch you are wielding the power of polymorphism. Each chain is implementing the chain interface and the constructor, that takes the next 'link' in the chain as an argument, is only expecting some concrete component that implements that chain interface. It does not care what the component is and knows nothing about it's behavior, as long as it implements the interface it is expecting it is happy. This means that when we instantiate this chain we now have a very 'plug and play' type set up. We have effectively built a decoupled 'switch statement' that obeys the SOLID principles. This pattern is especially useful if you have some requests that require complex logic. Maybe in the case of some request we would like to call some service class? You wouldn't want a class with a large switch statement in it to direct it to a service based on a request type. If you find yourself building large switch statements you should most likely take a step back and reevaluate what you are doing bc that becomes difficult to maintain and produces rigid code. Obviously this is a very simple example but that is intentional. It draws the focus on the pattern and not complex algorithms. Excellent job.
@derekbanas12 жыл бұрын
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
@derekbanas12 жыл бұрын
Yes I changed it to my name and connected my Google+ account. Nice catch :) I can't believe you noticed
@derekbanas11 жыл бұрын
That sounds like an interesting solution! Give it a go
@derekbanas12 жыл бұрын
This is a Java tutorial. This is a tutorial mainly about how to right good code using java. I'm sorry if I didn't make that clear
@derekbanas11 жыл бұрын
Thank you :) I try to do the best I can.
@derekbanas12 жыл бұрын
Hi :) That is very amazing to me. France seems like another world to a farmer boy like me. I have a bunch of SEO stuff on my site, but to be honest I don't know if ANY SEO tricks work anymore. I have however found a neat trick for drawing people to your links in search results. I'll try to make that tutorial very soon. LDAP will be covered in my upcoming networking tutorial. Thanks for the request
@derekbanas12 жыл бұрын
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
@derekbanas12 жыл бұрын
You're very welcome. Put them in the back of your mind or better yet on a note card. Eventually you'll start to see where they apply in the code you write.
@derekbanas12 жыл бұрын
Thank you :) I'll cover that in detail after I finish introducing the basics on what the patterns are. The topic you're looking for is called refactoring and I'll cover it in detail
@derekbanas12 жыл бұрын
You're very welcome :) Thanks for watching
@derekbanas11 жыл бұрын
You're very welcome. Thank you for watching them :)
@derekbanas11 жыл бұрын
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.
@derekbanas11 жыл бұрын
Yes, that is exactly the situation in which this pattern should be used
@derekbanas12 жыл бұрын
I think there are only 3 design pattern tutorials left. (Maybe 4?) Then I'll make the one you requested. It is very easy to do and I'll gladly handle that request because I've received it a bunch of times lately
@derekbanas12 жыл бұрын
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
@AsliAmine11 жыл бұрын
Well you have a nice and very clear style in teaching.. I wish you all the best success, I will continue watching your vids on Design Patterns no matter what is the language used to show exemples... Thank you again :)
@rawrs64888 жыл бұрын
I'm studying at uni right now and a lot of your videos make these concepts so much more understandable. Thank you very much sir! :)
@derekbanas8 жыл бұрын
Thank you :) I'm glad they help
@derekbanas12 жыл бұрын
Thank you SawMan :)
@isurucumaranathunga Жыл бұрын
Thank you so much this is so simple and to the point, Thanks Derek
@fabioesposito68238 жыл бұрын
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.
@NitinYadav-cs7yd8 жыл бұрын
Hey Fabio..... I don't know how to compare strings apart from using '==' , I guess Derek also don't know. Can you plz explain how to use equals to me and Derek ....... :P
@fabioesposito68238 жыл бұрын
Hi Nitin, I'm sure Derek knows it, you should do like this : "add".equals(request.getCalcWanted()) You could also write request.getCalcWanted().equals("add") but the first way is better because it avoids the possible NullPointerException if calcWanted happens to be null. I hope I was clear.
@NitinYadav-cs7yd8 жыл бұрын
Crystal clear !...... thanks for the explanation and your valuable time :)
@fabioesposito68238 жыл бұрын
You're welcome :) I forgot to tell you why == isn't good : it's because it compares the reference of the object in memory, two variables String with the same value in it, will have a different place in memory, so == will gives you false. Same goes for all objects, always use ".equals" and implement it on your classes if comparison is needed. Eclipse can do it for you : Source -> generate hashCode() and equals()...
@derekbanas12 жыл бұрын
Sometimes you can and you should use == if possible. == tests for reference equality while .equals() tests for value equality
@devilkillerz77710 жыл бұрын
Wow now i understand the chain of responsibility. Thanks so much.
@derekbanas10 жыл бұрын
You're very welcome :)
@alpinetech51563 жыл бұрын
You are the king Derek, great content
@derekbanas3 жыл бұрын
You are very kind :) Thank you
@FedJimSmith11 жыл бұрын
I'm glad I learned this pattern. But Sir, what do you think are the scenarios of best using this pattern rather than one method with switch statement?
@derekbanas11 жыл бұрын
Thank you :)
@ehenningsen10 жыл бұрын
These videos are simply awesome. Thank you for all the hard work
@derekbanas10 жыл бұрын
ehenningsen Thank you :) You're very welcome
@derekbanas11 жыл бұрын
I should do a tutorial on eclipse shortcuts. I use a bunch of them. Thanks for the request :)
@liquidation224 жыл бұрын
"pass the buck to other objects" that did it for me! I subscribed.
@derekbanas4 жыл бұрын
Thank you :)
@thestarinthesky_3 жыл бұрын
Still great and legend after 10 years!
@derekbanas3 жыл бұрын
Thank you :) I’m very happy that I could help
@idonar111 жыл бұрын
What about efficiency ? For every request the pattern will have complexity of O(N). that's a bit odd for performances isn't? isn't there any improvement - for example to use hashmap rather then a chain? thanks.
@maxim25o22 жыл бұрын
Greate and simple explanation :d I wish only to be in C++, but but whole design is not so different in the languages :)
@kfliden11 жыл бұрын
Does the pattern specify that each handler must break the chain if they execute the handler? or does it allow the handler to pass it on even though it handles it, or is that some other pattern? Also, I guess each handler must do a null check on the next handler in case the order is unspecified?
@manzell2 жыл бұрын
Could this be improved by using a Type argument? IE instead of checking for a text value on the request via GetCalcWanted, just create a request of type //etc? (coming from a C# perspective)
@antarikshverma89994 жыл бұрын
You are Awesome. Thank you for nice explanation.
@derekbanas4 жыл бұрын
Thank you :) It is my pleasure to help
@bernenortier44164 жыл бұрын
Hey! So you hardcoded the fact that DividenNumbers will always be last in the chain. Is this part of the pattern to have a 'last' handler? If not, how would you implement a chain of random order?
@Vendettaaaa66610 жыл бұрын
if i have a factory that decides which chain impl to use, i woundnt have to do chaining right? may be i would use this pattern if i have a chain of things to do and not to choose. what do you think Derek?
@rajdeepchauhan52512 жыл бұрын
Thank you. Very helpful
@derekbanas2 жыл бұрын
Thank you :) I'm happy I could help
@hikaru753911 жыл бұрын
And also at 4:50, is that copy text and add another copy ato the original method? That's cool, how to do that?
@billyclabough98352 жыл бұрын
Should this example use CoR? It seems more like a straight polymorphism problem. Would you please provide an example for CoR that would not be easier to solve using an abstract class and polymorphism?
@sachinpatel-pj4mb6 жыл бұрын
Hi Derek, Nice explanation. Can you please make a video for why and when one should use this pattern.
@ahmedgon17 жыл бұрын
very well explained, simple easy and smooth. Great work.
@derekbanas7 жыл бұрын
Thank you very much :)
@yuroso12 жыл бұрын
Hello Derek, i'm watching lots and lots of your videos and they're totally great! I'm learning a lot!!! Thank you so much! By the way, I want to propose you something. Do you know about algorithms complexity? This semester in university I studied how to calculate complexity of algorithms based on sorts, such as quick,shell,merge,heap,bubble,insertion, etc and I couldn't find any video that explains this stuff in a good and compreensive way. I'm sure you can do that and you woul help a lot of ppl
@ptekptek11 жыл бұрын
Hi Derek, This was the first time I felt the usefulness of the pattern was not so good. Maybe the situation it is handling is too simple. One could simply do a switch on the operation and since the same 2 operator variables are used on all operations, the result could be handled inside each case. Then, everything would be contained inside that switch and would result on less typing and quicker understanding of the code. Is there a more adequate situation when to use this pattern? thank you
@idonar111 жыл бұрын
Hi Derek. I would like to ask your opinion, this pattern fits the case of: Let's say I am the server and the client can be in different protocols (Htttp, jms, AnyOtherProtocol). When am I getting a request ill need to pass it via my chain till the right "adapter" will be caught and handle the request. Or that case would be connected to another Design pattern? Thanks!
@raulzuniga43829 жыл бұрын
Great tut! I am a bit surprised that Eclipse didn't flag your division as a possible divide by zero exception. I know, I know, at this level it is obvious and we'd put a try/catch around it. But IDEs are supposed to help us catch these types of things.
@WellingtonMateus8 жыл бұрын
Great job!!!! I am a big fan of yours!!!!
@derekbanas8 жыл бұрын
Thank you very much :)
@ZyncInteractive12 жыл бұрын
Cheers from Australia for these tutorials! Love your work. Not sure if you have done a Data Access Object tutorial yet but if you haven't is that on your to do list? Thanks again!
@pablohernandez43053 жыл бұрын
Thanks men great content.
@idonar111 жыл бұрын
But If I know in advanced the right "node" which should take care of the request("add","sub"..etc..) Why instead of "chaining" I shouldn't use "Hashing" then I just get the object from a hash-table and the key would be the name of the request. the brings us into O(1). what do you think?
@LordJosephDeBurg12 жыл бұрын
holy crap this is a good channel. instant sub! I will be recommending this to friends nice work derek!
@jamesbarrow12 жыл бұрын
Nice video :) Would you use the Chain of Responsibility pattern for implementing a workflow? Specifically long running workflows that could be persisted to the DB at any step, and resumed later? Would something else load up the state and pass it into the chain?
@ekmumeenmajungawala480712 жыл бұрын
hi Derek , great tutorials !!!, I am watching them from France and I find it awesome. If possible I would like to see subject on Search Engine Optimization and also on LDap.
@imadouzoun6 жыл бұрын
Extremely useful clip. Thank you for sharing it!
@derekbanas6 жыл бұрын
Thank you :)
@TimBee1009 жыл бұрын
Your example, plus others I have seen on the internet, has explained this design pattern to me. I'm still not sure if this is better than using a case statement to determine what class to call, which would be much easier. If you have to set up the chain order in the client program anyway, then you are going to have to change it when additional functionality is added, for instance first number to the second number power.
@DeweyWaspada928 жыл бұрын
I think the 'switch case' is better used for simpler statements. I couldn't much imagine if I had to put all those logical statements in my switch case block. That would be a very long one..
@ericcartmansh11 жыл бұрын
could this be done better by reading the responsibility chain from a xml file rather than have it coupled to the test class? Adding any methods to the chain in this implementation would require editing the code and recompilation, no?
@derekbanas11 жыл бұрын
You could try that. These patterns are just guides and not the set in stone way of applying them. My goal with each video was to explain them in an understandable way. There are numerous ways to implement the COR pattern
@ericcartmansh11 жыл бұрын
Makes sense. Thanks for replying :)
@derekbanas11 жыл бұрын
ericcartmansh Not a problem. I do my best to answer every question. It is just harder since the comments changed on KZbin. If I ever don't respond leave a message on my site to make sure i see it.
@ericcartmansh11 жыл бұрын
Will do. Keep up the great work!
@PrasanthMarimuthu4 жыл бұрын
@Derek Banas, Great tutorial, Could you please provide any real time examples for this pattern?
@revolverkid9112 жыл бұрын
Is this pattern ok for say i got four classes which deals with four different types of files. Or is there a better pattern to use?
@akhileshvvn5 жыл бұрын
awesome explanation......:)
@hikaru753911 жыл бұрын
Thank you for sharing. These stuff are really helpful. Btw, can i ask you something not really about the content but eclipse? i see what you do at 3:28, how can you do that with hotkeys? i think it's not the usual alt+shift+s method. And at 3:40, how do you replace the number 1 with 2 without ctrl+f. i really want to know, thank you.
@zakariaamine888 жыл бұрын
Thanks for the explanation. One question: from a real world point of view, isn't it up to the object to determine the type of command he is going to apply, and accordingly if he is going to call next or no ?
@_slier11 жыл бұрын
which one better to tame nested if? i dont know which one are better..either cor or state pattern? please advice..
@MouliDisturbs11 жыл бұрын
Instead of checking with thw string can we use instanceOf()
@pradiplamsal14034 жыл бұрын
Beautiful.
@dzigerica6666 жыл бұрын
this could be used to replace nested if statements right?
@gleytonlima380110 жыл бұрын
There should be an abstract class somewhere in the implementation?
@jonavuka10 жыл бұрын
I can see this being merged with a facade, where it manages all the classes, like the user doesn't have to instantiate each class like in this case a chain class for mult, add, sub and div...that way its less messy on the client side
@derekbanas10 жыл бұрын
Yes very often mixing patterns is a great idea. I cover more on that in the refactoring tutorial.
@TheDivergable12 жыл бұрын
I know, I meant I have commented about some things I wanted to know like how to place all of the classes into a jar file and then make an .exe file and you said that's going to be after the Design Pattern tutorials and I was just wondering when are the new Java tutorials. :)
@mohammadrezapourtorkan85952 жыл бұрын
Love this one!
@derekbanas11 жыл бұрын
The Strategy pattern is normally the best for that
@HenrykKwak5 жыл бұрын
Well done, thank you for your work!, but there is one issue with your example, worth to be pointed ( I know this is an old video ;) ). The implementation of setNextChain is repeated multiple times which means it does not follow DRY, a very simple but important principle. As the setNextChain implementation is common for all Chains it should be moved to an abstraction from these concrete classes by creating the AbstractChain class having the method setNextChain and making all concrete chains extending it. I am aware this is not a part of this particular pattern, but as many new devs are watching this, it would be useful to make at least a note in the video description and update the code examples ?
@davidboeger67662 жыл бұрын
Great point, but note that not all languages support polymorphism, Go being a prominent example. I believe you can still do something similar with Go's interfaces (I'm not a Go programmer), but I imagine it's possible to end up in a somewhat contrived scenario with such constraints. There are limits to the DRY principle, and there has even been a trend in recent years to duplicate small amounts of implementation code across multiple related types to avoid the complicated mess of super() calls that used to be common beginner traps in languages like C++. Detailed optimization is ultimately context-specific, and I think the way the video demonstrated the pattern conveys its overall intention.
@derekbanas11 жыл бұрын
That us one common use :)
@jeffreywillis95 жыл бұрын
Derek I have been a subscriber to your channel for a while, especially the Design Patterns (DP) series. Question what process should I use to determine when a DP is applicable?
@pr0master12 жыл бұрын
Perfectly explained. I thank you the "+" time(s) for your videos! :D
@AsliAmine11 жыл бұрын
My pleasure friend... I will check that Tutorial asap.. Thank you !
@noy2005212 жыл бұрын
Excellent! Thanks
@specialsounds3411 Жыл бұрын
it's better to use equals to compare Strings thanks for the vid mate
@derekbanas12 жыл бұрын
No hay de qué :)
@cafecomyogurt11 жыл бұрын
Huumn.. the example in the video did not convinced me that the pattern is the best solution for the problem presented. First of all, because the calculation classes (add, subtract, divide, multiply) have all the same code (duplication! :S ) I'll go for the solution using only a class with an if. I know if isn't beautiful, but either duplication of code is! Is there an example where the pattern is the best solution?
@derekbanas11 жыл бұрын
The goal was to make the pattern easy to understand. Normally with simple problems patterns aren't needed at all, but I went with that trade off in exchange for making it understandable. I know the example is perfect. Sorry about that.
@cafecomyogurt11 жыл бұрын
Yes.. I thougt that was the reason. I thougt this pattern a little hard to understand (why it can be good...) But, that's ok. I love your videos, and learn almost all that i know today, about design patterns, with your videos. Keep the good work. COngrats! Regards from Brazil
@derekbanas11 жыл бұрын
Café com Yogurt Thank you for being understanding. I have to constantly make judgement calls on how to cover these topics because there aren't that many books on the topic. I wish I was in Brazil right now :)
@vm16624 жыл бұрын
Great content and love the design pattern playlist. Thank you so much :)
@AsliAmine11 жыл бұрын
This is what we call the KISS KISS principle.. It was really very easy to learn and understand again.. But I think I need more and more examples from real life to see the real benefit of such pattern.. Can you give us more examples plz ?
@mahmudiftekharzamil79725 жыл бұрын
Hello. Your videos are amazing. One request, could you publish design patterns in swift videos or as a series. Although design patterns are language independent, it would be helpful if you publish such videos.
@derekbanas5 жыл бұрын
Thank you very much :) I'll see what I can do
@MrBrownpotato10 жыл бұрын
very cool, Thanks! I would add some Default() handler at the end of the chain which prints "operation not supported"
@derekbanas10 жыл бұрын
Thanks for the input :)
@MrBrownpotato10 жыл бұрын
Derek Banas These tutorials are excellent! Your way of presentation makes my pattern anxiety disappear.
@kony20237 жыл бұрын
Thanks great video!
@derekbanas7 жыл бұрын
Thank you :)
@bryanttran207 жыл бұрын
Question: I'm seeing this similar to a linked list, is that correct?