Studying for a Software Engineering exam right now, and Design Patterns were explained so horribly. You are a savior!
@derekbanas10 жыл бұрын
Dennis Grzyb Thank you :) Best of luck on your exam.
@konradciezarek833310 жыл бұрын
Hahaha funny thing to see my fellow students in KZbin :D Derek you seem to save our classes!
@sunmustbedestroyed10 жыл бұрын
Konrad Ciezarek *Classes* - snorts of laughter -
@crazyingenieur32775 жыл бұрын
As a hobbyist web developer (mechanical engineer), I am loving your design pattern tutorials with realistic examples!! I have been searching tutorials/examples on the internet, including here on KZbin, and have not seen anyone that can be compared to you. Thank you!
@derekbanas5 жыл бұрын
Than you for the nice compliment :)
@derekbanas11 жыл бұрын
Sorry about that. Here it is kzbin.info/www/bejne/noOrn3utZ7GJmK8 It is my Code Refactoring pt 13 tutorial. It covers the command pattern again
@connectmkp11 жыл бұрын
Firstly Thanks and appreciate your effort for us. I think, by this time, you'd have already created all the videos. It would be really helpful if you could explain the problem and then implement the particular design pattern which would make these tutorials stay in our minds forever. Once again Thank you!
@joeemenaker10 жыл бұрын
In your PlayWithRemote class, I think it's better form to, instead of using: TurnTVOn onCommand = new TurnTVOn(newDevice); use Command onCommand = new TurnTVOn(newDevice);
@The28studio6 жыл бұрын
He's just doing the L in Solid.
@smartwerker5 жыл бұрын
lmao
@shankar743511 ай бұрын
Better naming would be like --> Command tvOnCommand = new TurnTVOn(newDevice); I also guess He forgot to have RadioOn class in his code. Am I correct?
@derekbanas12 жыл бұрын
I'm going to cover Java EE and the associated technologies in a separate tutorial. Pretty much every request I've received lately will be covered in that tutorial including anything that has to do with networking. Don't worry I'll get to it :)
@derekbanas12 жыл бұрын
Thank you :) I'm always happy to hear that I helped. Thanks for taking the time to tell me the video was good
@jonacierto7107 Жыл бұрын
I really appreciate the teaching style, it's so easy to follow along. Thank you Derek Bananas.
@derekbanas Жыл бұрын
Thank you for taking the time to write such a nice message :) I greatly appreciate it!!!
@adamwhalen95194 жыл бұрын
This entire series is AMAZING! Thank you so much for providing this for free to the world!
@derekbanas12 жыл бұрын
You're very welcome :) I cover all 24 patterns by the end
@derekbanas11 жыл бұрын
Design Patterns are really just guides that an advanced programmer can use to write clean understandable code. They aren't recipes like you are more then likely use to. Once you learn basic syntax you eventually will see that programming is a form of art and you must work to truly master the medium. At this point I don't think there are any real rules except that code should be flexible and understandable. Patterns help you do that.
@MuhammadBilal-pi2su10 жыл бұрын
I am a student of Computer Sciences and your video tutorials have really helped me in preparing for my exams. Many thanks...
@lanklaan9 жыл бұрын
Hi Derek, great tutorials. Maybe you can add complete class diagrams of the programs you create during the video's.
@kelemeno4 жыл бұрын
I love so much about this video. Articulate, confident, prepared, informed, quick, simple. Thank you Derek Banas. I see you're doing pretty well on the Tube and wish you more success in the future.
@derekbanas4 жыл бұрын
Thank you very much 😁 I'm happy I could help
@EminoMeneko2 жыл бұрын
I'm learning Design Patterns with C#. I love the clarity of that video.
@shankar743511 ай бұрын
You just showed what hard work does ? Improving others life. You deserve more subs and great respect. ❤❤❤
@derekbanas11 жыл бұрын
You could go that route. I have always looked at these patterns as guides rather then as set in stone rules. For the most part though, I followed the GOF rules when I made them in this tutorial
@derekbanas11 жыл бұрын
Thank you :) If I'm understanding your problem, it sounds like method overloading would solve it
@derekbanas11 жыл бұрын
Thank you very much :) What would you want to see in a prolog tutorial?
@123japanuser12 жыл бұрын
Hey Coach , this time FASTEST FINGER FIRST YAY !!!!!!!! Thanks for sharing this and stay blessed as ever .
@derekbanas12 жыл бұрын
Thank you :) I'm glad you enjoy them
@BobTheZealot7 жыл бұрын
A true technological breakthrough... A TV that can change volume even when it's off!
@rickmonarch45526 жыл бұрын
My brother trolled me with turning colume max and switched it off. Then I went home at night and turned it on.. My neighbors hate me since.
@The28studio6 жыл бұрын
if the volume button is manul (like old TVS) you can do that . But you're case is actually when of the issues these pattern have sometime , let's take the TV , if it's all digital , you shouldn't be appl to to call vollume Up , so you will need to setup some chacking , easy fix will be a boolean on the TV object to tell you it's status
@sivakumarthanikanti76796 жыл бұрын
just why dont you take the concept
@derekbanas11 жыл бұрын
Thank you :) Sorry about the monotone voice. I normally do that so it is easier to edit the video.
@derekbanas12 жыл бұрын
You're welcome :) you can solve many common problems with design patterns
@derekbanas12 жыл бұрын
You're very welcome :) I do my best
@rachelr224 жыл бұрын
Don't know what to do without your tutorials! Thank youu
@derekbanas4 жыл бұрын
Thank you for the nice compliment :)
@KingMartinelli9 жыл бұрын
Thank you Derek! I am also studying right now for my software engineering exam!
@derekbanas9 жыл бұрын
KingMartinelli You're very welcome :) i wish you the best of luck.
@ImmunityG5 жыл бұрын
I like how this example is also an example for one of the SOLID principles which is the Single Responsibility Principle and that's why I don't think its a negative that you have multiple classes because this reduces the dependency of your code.
@Carlomanization10 жыл бұрын
Uoooh!!! The TV is turned off, but you can still turn up the volume!! Very powerfull the command pattern, cool!! By the way great tutorials!
@derekbanas10 жыл бұрын
Thank you very much :)
@krispybutter25552 ай бұрын
The best way I understood this pattern is if you want a set of consistent, predictable behavior, this works well. If you're looking for undo/redo functionality, this is a good option too. So say in like in an e-commerce application, placing an order might involve multiple steps like checking inventory, processing payment, and updating order status. Each step can be a command, and the entire process can be treated as a transaction. Another example could be like in a home automation system, you might want to create a “Good Night” button that turns off all lights, locks doors, and sets the thermostat. Each of these actions can be a command, and the “Good Night” button can execute all these commands in sequence. The design of the command I thought of like this: Receiver class is the collection of behaviors, say a Light class with methods on() and off(). You'd then create a command class for each method in the receiver class. So all behavior is pooled together and called on a polymorphic execute command. The involker class just takes in commands and calls execute or organizes how to deal with multiple commands or whatever you want to do with it.
@ListRav178 жыл бұрын
Thank you for the video! In my class I just got thrown into many design patterns and client/server networking and a bunch of stuff I've never worked with. But you going through the code while writing it out helped me to understand this much better!
@derekbanas8 жыл бұрын
I'm very happy that it helped :)
@edcartagena1007 жыл бұрын
Great explanation and code examples. I've viewed a few other videos and articles but your the first one to make it click (pun intended) in my mind.
@zoaltamam3 жыл бұрын
This is awesome! AWESOME!!!! I have watched probably all your design patterns series, but this is by far the coolest! I was wondering for a while about how on earth does one implement a solid undo functionality in an application, something as amazing as what Microsoft has going on with most of its office apps. This video is a huge help bro! Though it’s been 8 years since you made this, I would like to thank you a ton right now
@derekbanas3 жыл бұрын
That is fantastic! I'm very happy that you are enjoying the series
@SVN77KMF8 жыл бұрын
As always with your tutorials: a pleasure to view, learn and recap.Deep respect for this great work!
@derekbanas8 жыл бұрын
Thank you :) I'm happy you liked it
@pging83287 жыл бұрын
Thanks for this. I understand the pattern, but I still don't quite understand the utility of it all. What are the advantages of using this pattern?
@GuRuGeorge033 жыл бұрын
I know I am 4 years late but the pattern allows u to send generic, easy to understand commands to a variety of different devices, like for example on/off without needing to know how those commands work internally, since the logic is encapsulated completely. For example in the real world u press the off button of a TV or machine, but what happens inside the device is actually unkown to you (unless you are an engineer that built the device, in the example of the video it is the logic outside of the main function). PS: the video shows the most abstract/flexible version of the pattern. In 90% of cases, it is enough to have every electronic device implement the same interface which u can then use from the main function
@northstar400411 жыл бұрын
Very good explanation........... But please if can tell more as where it should be used and where not with some real life examples... Or is it only best adapted for Undo feature only?
@derekbanas12 жыл бұрын
Thank you :) Yes you win the award for being FIRST today!
@derekbanas11 жыл бұрын
Because TVRemote is a utility class and it isn't meant to be anything else
@kitokopter11 жыл бұрын
Keep up with good work! Not only have you helped me with my test, but I have actually learned something here o/
@derekbanas11 жыл бұрын
Great I'm glad you found it useful :)
@derekbanas12 жыл бұрын
Siete i benvenuti! Quante lingue conosci?
@PizzaPartify11 жыл бұрын
I love your videos ! My only small criticism is that your voice is super energetic at the start of the video but is a little monotonous when you are half-way through the code.
@hexrcs26416 жыл бұрын
At 10:30 why do you have to keep a reference to the Command instance in the invoker? Why not just pass that Command into the press() method as an argument and make the Invoker completely static?
@scrapdinesh12 жыл бұрын
I have followed some of the tutorials. Its really great!
@OmprakashYadav-nq8uj Жыл бұрын
Great video overall. One question : why have you not used interface segregation principle for device interface (on,off) and (volumeUp, volumeDow) ?
@davidharrington11333 жыл бұрын
in .NET commands also have a boolean CanExecute property that can be used to enable and disable controls automatically in a bound UI. Great explanation.
@Joske36911 жыл бұрын
thanks for the fast answer on my questions in the other videos, but i have another question , the class diagram for the command pattern shows that there is no relationship between the client and the invoker, but in the same example in my book they make a new object from the invoker class in the client, is this an error in my book u think or does making a new object from another class not necessairily mean a relationship between objects?
@MsKostas74 жыл бұрын
I got the concept but i didn't really understand why didn't we just used the method of the electronic device straight up. Instead of using a new class just to invoke a method in my original electronik device why didn't we do something like myElectronicDevice.volumeUp(); ?
@123japanuser12 жыл бұрын
Derek , Have you already covered Data Access Object and JDBC , JNDI ? There is hardly an enterprise Java Project without these " TORMENTORS" :( of mine.
@chriskerley15088 жыл бұрын
Clear speaking, and a thorough explanation. My only critique is the order in which you explained it. It would have been easier to understand if it was explained in a top down manor rather than a bottom up. For example, the code that supports the pattern was written before the code in the main method was written, (which is the direction I code in when I have the design settled on). However, when doing design, or learning things, I find it is much easier to start at the abstractions first then work down to the details, (the code).
@derekbanas8 жыл бұрын
Thank you and you made a great point about how I could improve the explanation :)
@josefsabl6 жыл бұрын
Thank you, I think I understand the command pattern bit better now, but the undo part is just messed up as undo doesn't work like that. I guessed you should have used some registry, record the commands and then replayed them backwards in the undo mode?
@ИльясМаметов-и1о Жыл бұрын
Hi, great video! thank you for sharing. Sometimes I think why encapsulating is needed in the first place. Why can't we just work with device object. pass it and call the method, that we want to call. The answer is: to make code less coupled. When we create a command, the interacting part is represented in a small functionality. The end-user of command interface don't affect or depend on original device code. In the presented code, device is created by ourself. But in practice, device code can come from third-party libraries. We may not have control over them. In the examples of the video, it may not be clear, because all the code is created by ourself and may be changed by ourself when we need it. And second benefit of creating command, that we don't change the original code of device. For example we don't force the device code to implement our custom interface. I hope this make sense
@khxml12 жыл бұрын
I'm glad you have covered Command and Memento, thanks!
@marwanjabbour37393 жыл бұрын
The undo for turnAllOff is not accurate because you're assuming that everything was on before calling turnAllOff. You should restore the previous state of the Electronic Devices.
@smartwerker5 жыл бұрын
Some people don't understand that this is used to solve a problem that is commonly known. If you have not experienced a system that requires this pattern cool, but sooner or later when you start looking for solutions in complex systems you'll find the "patterns" useful instead of reinventing the wheel.
@joeemenaker10 жыл бұрын
Two things: First, the "Command" pattern just turns a method/function into a class (in your example, a class of the same name as the method it calls) for languages which don't support passing functions as arguments. It's very heavy on the use of wrappers. Second, your DeviceButton class is very similar to the Command class that it makes use of, in the sense that it just calls a pre-determined method of an object which you give it at instantiation (just like your Command subclasses)
@jeffreywillis911 жыл бұрын
Derek love your tutorials. What design pattern would you suggest for a queuing ssystem?
@slavariv11 жыл бұрын
as usual, great tutorial! i have only one question, lets say I've some kind of Element class & I want it to be able to fulfill "addNewElement" command. I could convert the action of "add" into the command interface, but the problem is it has to take 1 parameter otherwise you won't know what to add. so the question is, do I add another method to the interface "executeWithParams(T param)" or there is a better solution?
@derekbanas12 жыл бұрын
The homework is totally optional. I only provide it because I'm asked for homework all of the time. I think the solution is pretty simple though
@bencris5102 жыл бұрын
These videos are gold!!!
@northstar400411 жыл бұрын
Thanks for the quick reply but the link u mentioned returns message "Sorry, the page your requested could not be found, or no longer exists." on the newthinktank website. :-(
@emanuelmatlhaku47848 жыл бұрын
Dude, my software design professor's got nothing on you, thank you very much
@derekbanas8 жыл бұрын
Thank you for the compliment :)
@nolimangulabnan61013 жыл бұрын
Thanks for this video, very helpful. BTW, why do - class TVTurnOn has a member ElectronicDevice? My Idea was - TVTurnOn should have a Television member, because the class TVTurnOn is already for TV and not for other type of ElectronicDevice. Is my idea is correct? and if not why ElectronicDevice makes more sense to use? Many thanks for the answer. newbie here :)
@Lexyvil2 жыл бұрын
So it's basically having a class that acts as a command rather than an object?
@Joske36911 жыл бұрын
there's no specific pattern for a queue/circular queue, u can write the whole queue system itself in 1 class. only when you want to add items that are specific polymporphic types you could use a factory; or the observer pattern to show the first item in the queue
@suchismitagoswami56092 жыл бұрын
As always an awesome tutorial. I have a little observation here. Insteed of TurnTVOn, can we rename it as TurnDeviceOn as its a command and can work on any receiver.
@ajperras233510 жыл бұрын
Fantastic tutorial - this helps quite a bit!
@derekbanas10 жыл бұрын
***** Thank you very much :)
@joaoserrano3125 жыл бұрын
Hey Derek great tutoria, thank you! Maybe just one improvement would be to comment the corresponding UML name in the code class would def. help in memorizing
@shyamtripathy50847 жыл бұрын
Why is the abstraction required with an extra class DeviceButton ? Arent we over complicating things a bit. Also, I would be interested to understand, an use case where you used this pattern. Good stuff!!!
@detectivedonaldkimball4 жыл бұрын
i have the same questinos, why add devicebutton?
@AlexEttelis12 жыл бұрын
When you say "Object object; Object object2=new Object; object=object2" It assigned the address of object2 to object and you can use it normally?
@MrQwerty25247 жыл бұрын
Why do you even need polymorphism when creating a class as specific as 'TurnTvOn'? You might as well make newDevice of type Television instead of electronic device, right?
@SeaDadLife7 жыл бұрын
Good question - it gave me reason to watch the video again. I would say the use of ElectronicDevice instead of Television means that one could use the command TurnTvOn and pass it a Radio -- everything would work just fine. I suppose one could rename the TurnTV* command classes to TurnDevice* if that seems clearer.
@sipanarevshatyan63548 жыл бұрын
Derek our Television is OFF but we can increase or decrease the volume (15:50). Should not we stop this functionality while TV is off?
@derekbanas8 жыл бұрын
+Sipan Arevshatyan Yes that would be a good idea. I wrote the code out of my head so it isn't optimized.
@sipanarevshatyan63548 жыл бұрын
+Derek Banas Trying to find something wrong in these perfect tutorials :D
@tikarobinson93359 жыл бұрын
I have a few questions, with command pattern, there is always going to be a interface? Also you will use the command pattern for things you would like to turn off and on and that have certain levels such as volume and etc.?
@jinizzraeel77059 жыл бұрын
Why you state the undo method as a specific feature of command pattern? It looks like it can be implemented in other patterns. Thank you.
@derekbanas9 жыл бұрын
Jin Izzraeel In this situation the undo method is normally considered a requirement rather then an option.
@dhedarkhcustard10 жыл бұрын
What about something like a paint program where you draw an obscure random scribble? Would it be better to cache each layer's data for each unto or would it be better to say delete the entire layer and then run through each command 1 by 1, copying what you did, until it gets to the second last one?
@dhedarkhcustard10 жыл бұрын
What about something like a quad-tree where it caches a bunch of grid areas and only undoes the ones you collide with?
@derekbanas10 жыл бұрын
I made a Java paint tutorial here www.newthinktank.com/2012/06/java-video-tutorial-48/
@sai80080 Жыл бұрын
Hi, I find this same as Bridge Design pattern. Can you please explain how this is different?
@GG-uz8us6 жыл бұрын
Would it be better if you rename the class TurnTVOn to TurnDeviceOn, etc.?
@aaron___60148 жыл бұрын
Can someone point me towards videos or topics on taking a commandline argument, making it into an array, and then inserting a linked list into that array? Thanks
@shimonbalzera86188 жыл бұрын
Hi Derek, First you do good work! Can you please explain to me the difference between command and strategic patterns? They both looked so Identical. Thanks
@reemibrahim403911 жыл бұрын
for example how can we do simple games or puzzle in prologue applying Specific search algorithms
@michaelbrooks67136 жыл бұрын
I'd like ask, if it's a good approach to have the device return a value from it after it's executed or would that be another pattern I should look at like Observer or something?
@andrecelestinodev8 жыл бұрын
Fantastic tutorial, Derek! Good job! I have a simple doubt. In your video, you created a list of devices to turn them off all at once. Could I create a list of commands in my Invoker so that I add (and queue) commands to be executed later at the same time?
@arminoldboy9987 жыл бұрын
thanks again. I'm seeing this design pattern tutorial but I think I can't understand the main idea of each pattern !! can u help me Derek ? or interduce a reference site? for example when we most use the Abstract pattern or when we most command?
@derekbanas7 жыл бұрын
This tutorial series was made to make the book Design Patterns: Elements of Reusable Object-Oriented Software amzn.to/2v5R80N easier to understand. That book might help you understand DPs better.
@arminoldboy9987 жыл бұрын
thank u very much Derek .i also asked some question in newthinktank.com .I hope u answer me.
@Brax19829 жыл бұрын
Since Java 8 introduced default methods into interfaces, you can add the undo as an empty default method to the Command interface and avoid implementing it for every single class that implements this interface.
@SwissExperiments9 жыл бұрын
Thank you Derek, I've studied all patterns through your videos and I really understood them well. I have one question tho regarding this one. What should I do if (for example) the TV needs to know which "remote" executed the command? Should i pass it as argument when calling execute or is it better to pass the object by constructor? If the latter, then how can i know the object already when constructing the command? Greetings
@derekbanas9 жыл бұрын
+Swiss Experiments - Castagnola007 You're very welcome :) You could assign a unique id for each remote. I like to think what the real world object would do and base my design off of that.
@Basta116 жыл бұрын
Seems to me the main parts are simply the Target, Command, and Invoker. A Target obj - which could be any device which has its methods. A Command - which contains a device, and the execute method. The execute method just calls a method in the device. Invoker - is just an object that contains a command, and a method which calls the command execute method. Examples. Device - TV, Radio, Robot, Vehicle, Lamp, fan, Phone, Weapon Command - on, off, change settings, move, fire, Invoker - button (press), switch (toggle), lever (pull), knob (turn), listener (event),
@gabrielferrer24008 жыл бұрын
Why was the ElectronicDevice implemented instead of being inherited?
@rickmonarch45526 жыл бұрын
I have to learn all of these patterns in 3 days for my teacher. I love Hungary xD... and it's just 3/13 th part of the subject. Exam is coming. I'm lucky I can watch these. Only these videos need no observation cus it has an aim so i can guess the details by iq so I don't need to be observant :))
@terushkanaidoo51259 жыл бұрын
your video was really helpful!! can you post the uml diagram for this example please
@artolaganus4 жыл бұрын
With this undo I an call undo before execute or undo twice ... or am I wrong
@jamesviago8 жыл бұрын
hi Derek. great series. in the intro to this video you describe the primary use of the command pattern being to store a list of commands for later execution. but in the body of the video, the commands execute immediately. is it still useful to use command pattern if there is no need for delayed execution? and if so, what's the advantage? the extra classes seems a heavy price to pay if there's no need to queue them.
@jonispatented Жыл бұрын
Typically, you'd include two methods in the Command interface: execute() and undo(). If you store a list of Commands you can get the most recent Command, undo() it, and pop it off the stack. Makes the undo function of your app trivial to implement.
@reemibrahim403911 жыл бұрын
I loves your tutorials (designe patterns and android )very much .But have you tutorials about prologue either i would be thankfull.
@ramkumarnj76177 жыл бұрын
Great Video. Simple and very effective!
@derekbanas7 жыл бұрын
Thank you very much :)
@devnull196910 жыл бұрын
Great tutorial. I'm just confused about why you call the commands TurnTVOn and TurnTVOff respectively whereas they are meant to actually TurnDEVICEOn or TurnDEVICEOff, aren't they?
@derekbanas10 жыл бұрын
devnull1969 Thank you :) Yes I like your names better
@migueldev5310 жыл бұрын
Derek Banas You should really add a note in your video man that's really confusing. . . . . . .
@shankar743511 ай бұрын
Are we missing RadioOn & RadioOff classesin the source code?
@ballisticbuddha10 жыл бұрын
Quick question about the command methods. How would one go about giving the execute() method of some commands an argument while still having other commands that don't have arguments? For the sake of this example, how would you go about implementing a setVolume(int volumeLevel) command in the reciever? I see how it's possible to do this in the reciever, as this is where the actual data manipulation is done, however, giving an argument to just the SetVolume command, would break the consistency of having all commands implement the same interface. Edit: So I've since made these arguments set as instance fields in the constructor, so each concrete object defines any needed arguments from arguments to the constructor. I guess this works, is there a better way, or is this what you would recommend? -Thanks
@jonispatented Жыл бұрын
That's the correct solution. Each object of the Command class represents a single solitary command and needs to store all the information it needs. Typically, the Command interface will have two methods: execute() and undo(), and you need to store the volume adjustment as a field in the command object so you can use it again in the undo method.
@derekbanas11 жыл бұрын
Thank you :) Yes a stack would be quicker
@DellAnderson10 жыл бұрын
Great command pattern tutorial! I think I actually 'get it'. However, I'm still a little fuzzy on the rationale behind it all -- isn't this kind of pattern basically 'breaking' OOP concepts of state and action by converting methods into class objects? Perhaps this is why some of us have problems relating. It's one thing to understand that a bicycle object has gears (fields) that can be shifted (methods). It's quite another to make the process of shifting them into a class object. Something just feels wrong about it. Thoughts?
@Brax19829 жыл бұрын
***** OOP is not bound to our real-world models and logic.
@jacqueterrell84467 жыл бұрын
Dell Anderson 😬
@sheentoosi96427 жыл бұрын
Hey Derek, can you do a implementation of the Command design pattern in a real life situation such as in a Command design pattern in a Model View Controller?I did an assignment where I had to do just that in a paint program and was honestly stumped. Love your videos :D
@bilolboydedaev95544 жыл бұрын
Very helpful video keep up the good work man
@derekbanas4 жыл бұрын
Thank you Happy I could help :)
@abhishekagrawal33089 жыл бұрын
Great Video!!!.One Suggestion: At the end of each DP video if you can add examples from Java APIs then i think it will be very helpful.
@derekbanas9 жыл бұрын
+Abhishek Agrawal Thank you :) I plan on doing more on DPs. Thank you for the input.