Command Design Pattern

  Рет қаралды 283,067

Derek Banas

Derek Banas

Күн бұрын

Code is Here: goo.gl/haF7p
Best Design Patterns Book : goo.gl/W0wyie
Welcome to my Command Design Pattern Tutorial! The Command design pattern allows you to store a list of commands for later use. With it you can store multiple commands in a class to use over and over.
I cover the basic pattern in numerous ways including descriptions, diagrams and code. We look into executing commands on numerous objects. We also explore how to undo commands.
All of the code is above. Between it and the video you should be an expert on the Command Pattern.

Пікірлер: 266
@dennisg.517
@dennisg.517 9 жыл бұрын
Studying for a Software Engineering exam right now, and Design Patterns were explained so horribly. You are a savior!
@derekbanas
@derekbanas 9 жыл бұрын
Dennis Grzyb Thank you :) Best of luck on your exam.
@konradciezarek8333
@konradciezarek8333 9 жыл бұрын
Hahaha funny thing to see my fellow students in KZfaq :D Derek you seem to save our classes!
@sunmustbedestroyed
@sunmustbedestroyed 9 жыл бұрын
Konrad Ciezarek *Classes* - snorts of laughter -
@crazyingenieur3277
@crazyingenieur3277 4 жыл бұрын
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 KZfaq, and have not seen anyone that can be compared to you. Thank you!
@derekbanas
@derekbanas 4 жыл бұрын
Than you for the nice compliment :)
@joeemenaker
@joeemenaker 10 жыл бұрын
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);
@The28studio
@The28studio 5 жыл бұрын
He's just doing the L in Solid.
@smartwerker
@smartwerker 5 жыл бұрын
lmao
@shankar7435
@shankar7435 7 ай бұрын
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?
@derekbanas
@derekbanas 11 жыл бұрын
Thank you :) I'm always happy to hear that I helped. Thanks for taking the time to tell me the video was good
@derekbanas
@derekbanas 11 жыл бұрын
You're very welcome :) I cover all 24 patterns by the end
@EminoMeneko
@EminoMeneko 2 жыл бұрын
I'm learning Design Patterns with C#. I love the clarity of that video.
@BobTheZealot
@BobTheZealot 7 жыл бұрын
A true technological breakthrough... A TV that can change volume even when it's off!
@rickmonarch4552
@rickmonarch4552 6 жыл бұрын
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.
@The28studio
@The28studio 5 жыл бұрын
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
@sivakumarthanikanti7679
@sivakumarthanikanti7679 5 жыл бұрын
just why dont you take the concept
@connectmkp
@connectmkp 11 жыл бұрын
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!
@lanklaan
@lanklaan 8 жыл бұрын
Hi Derek, great tutorials. Maybe you can add complete class diagrams of the programs you create during the video's.
@MuhammadBilal-pi2su
@MuhammadBilal-pi2su 9 жыл бұрын
I am a student of Computer Sciences and your video tutorials have really helped me in preparing for my exams. Many thanks...
@shankar7435
@shankar7435 7 ай бұрын
You just showed what hard work does ? Improving others life. You deserve more subs and great respect. ❤❤❤
@adamwhalen9519
@adamwhalen9519 3 жыл бұрын
This entire series is AMAZING! Thank you so much for providing this for free to the world!
@derekbanas
@derekbanas 12 жыл бұрын
Thank you :) I'm glad you enjoy them
@jonacierto7107
@jonacierto7107 Жыл бұрын
I really appreciate the teaching style, it's so easy to follow along. Thank you Derek Bananas.
@derekbanas
@derekbanas Жыл бұрын
Thank you for taking the time to write such a nice message :) I greatly appreciate it!!!
@derekbanas
@derekbanas 11 жыл бұрын
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.
@derekbanas
@derekbanas 11 жыл бұрын
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
@derekbanas
@derekbanas 11 жыл бұрын
Thank you :) If I'm understanding your problem, it sounds like method overloading would solve it
@derekbanas
@derekbanas 11 жыл бұрын
You're very welcome :) I do my best
@kelemeno
@kelemeno 3 жыл бұрын
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.
@derekbanas
@derekbanas 3 жыл бұрын
Thank you very much 😁 I'm happy I could help
@KingMartinelli
@KingMartinelli 9 жыл бұрын
Thank you Derek! I am also studying right now for my software engineering exam!
@derekbanas
@derekbanas 9 жыл бұрын
KingMartinelli You're very welcome :) i wish you the best of luck.
@rachelr22
@rachelr22 4 жыл бұрын
Don't know what to do without your tutorials! Thank youu
@derekbanas
@derekbanas 4 жыл бұрын
Thank you for the nice compliment :)
@derekbanas
@derekbanas 11 жыл бұрын
You're welcome :) you can solve many common problems with design patterns
@ImmunityG
@ImmunityG 4 жыл бұрын
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.
@Carlomanization
@Carlomanization 10 жыл бұрын
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!
@derekbanas
@derekbanas 10 жыл бұрын
Thank you very much :)
@zoaltamam
@zoaltamam 3 жыл бұрын
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
@derekbanas
@derekbanas 3 жыл бұрын
That is fantastic! I'm very happy that you are enjoying the series
@ListRav17
@ListRav17 7 жыл бұрын
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!
@derekbanas
@derekbanas 7 жыл бұрын
I'm very happy that it helped :)
@derekbanas
@derekbanas 11 жыл бұрын
Thank you very much :) What would you want to see in a prolog tutorial?
@123japanuser
@123japanuser 12 жыл бұрын
Hey Coach , this time FASTEST FINGER FIRST YAY !!!!!!!! Thanks for sharing this and stay blessed as ever .
@derekbanas
@derekbanas 12 жыл бұрын
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 :)
@edcartagena100
@edcartagena100 7 жыл бұрын
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.
@davidharrington1133
@davidharrington1133 2 жыл бұрын
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.
@SVN77KMF
@SVN77KMF 8 жыл бұрын
As always with your tutorials: a pleasure to view, learn and recap.Deep respect for this great work!
@derekbanas
@derekbanas 8 жыл бұрын
Thank you :) I'm happy you liked it
@pging8328
@pging8328 7 жыл бұрын
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?
@GuRuGeorge03
@GuRuGeorge03 3 жыл бұрын
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
@chriskerley1508
@chriskerley1508 7 жыл бұрын
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).
@derekbanas
@derekbanas 7 жыл бұрын
Thank you and you made a great point about how I could improve the explanation :)
@kitokopter
@kitokopter 10 жыл бұрын
Keep up with good work! Not only have you helped me with my test, but I have actually learned something here o/
@derekbanas
@derekbanas 10 жыл бұрын
Great I'm glad you found it useful :)
@bencris510
@bencris510 2 жыл бұрын
These videos are gold!!!
@derekbanas
@derekbanas 11 жыл бұрын
Sorry about that. Here it is kzfaq.info/get/bejne/nrh4oauol7K6koE.html It is my Code Refactoring pt 13 tutorial. It covers the command pattern again
@user-sz1jw2wt7v
@user-sz1jw2wt7v Жыл бұрын
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
@joaoserrano312
@joaoserrano312 5 жыл бұрын
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
@PizzaPartify
@PizzaPartify 11 жыл бұрын
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.
@smartwerker
@smartwerker 5 жыл бұрын
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.
@derekbanas
@derekbanas 11 жыл бұрын
Thank you :) Sorry about the monotone voice. I normally do that so it is easier to edit the video.
@MsKostas7
@MsKostas7 4 жыл бұрын
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(); ?
@emanuelmatlhaku4784
@emanuelmatlhaku4784 8 жыл бұрын
Dude, my software design professor's got nothing on you, thank you very much
@derekbanas
@derekbanas 8 жыл бұрын
Thank you for the compliment :)
@khxml
@khxml 11 жыл бұрын
I'm glad you have covered Command and Memento, thanks!
@joeemenaker
@joeemenaker 10 жыл бұрын
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)
@northstar4004
@northstar4004 11 жыл бұрын
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?
@ajperras2335
@ajperras2335 10 жыл бұрын
Fantastic tutorial - this helps quite a bit!
@derekbanas
@derekbanas 10 жыл бұрын
***** Thank you very much :)
@derekbanas
@derekbanas 12 жыл бұрын
Siete i benvenuti! Quante lingue conosci?
@derekbanas
@derekbanas 11 жыл бұрын
Because TVRemote is a utility class and it isn't meant to be anything else
@scrapdinesh
@scrapdinesh 12 жыл бұрын
I have followed some of the tutorials. Its really great!
@derekbanas
@derekbanas 12 жыл бұрын
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
@OmprakashYadav-nq8uj
@OmprakashYadav-nq8uj Жыл бұрын
Great video overall. One question : why have you not used interface segregation principle for device interface (on,off) and (volumeUp, volumeDow) ?
@abhishekagrawal3308
@abhishekagrawal3308 9 жыл бұрын
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.
@derekbanas
@derekbanas 9 жыл бұрын
+Abhishek Agrawal Thank you :) I plan on doing more on DPs. Thank you for the input.
@nolimangulabnan6101
@nolimangulabnan6101 3 жыл бұрын
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 :)
@xjsnjkil2070
@xjsnjkil2070 9 жыл бұрын
As usual, it is a masterpiece. Just wondering, is it also called "call back"?
@bilolboydedaev9554
@bilolboydedaev9554 4 жыл бұрын
Very helpful video keep up the good work man
@derekbanas
@derekbanas 4 жыл бұрын
Thank you Happy I could help :)
@SwissExperiments
@SwissExperiments 8 жыл бұрын
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
@derekbanas
@derekbanas 8 жыл бұрын
+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.
@shyamtripathy5084
@shyamtripathy5084 7 жыл бұрын
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!!!
@detectivedonaldkimball
@detectivedonaldkimball 4 жыл бұрын
i have the same questinos, why add devicebutton?
@rprasad1421
@rprasad1421 9 жыл бұрын
Great tutorial. I love all your tutorial you are simply awesome. Could you please cover these topic as well at your earliest convenience:- Enum Enum with complex problems example of Enum with Design patterns Json Object Mapper, JSon Node Restful Services with Java
@derekbanas
@derekbanas 9 жыл бұрын
R Prasad Thank you :) I covered many of those topics in my webservices tutorial kzfaq.info/get/bejne/n9d-nKx_v5q3qJs.html
@rprasad1421
@rprasad1421 9 жыл бұрын
Thanks Derek Banas but I was looking for REST services with JAVA & JSon using JSON node and Object Mapper which unfortunately dont see in this tutorial. Please create tutorials for these topics also it will be great if you can cover enum. Thanks in advance and you rock !!!
@FeedMyKids1
@FeedMyKids1 3 жыл бұрын
Sorry if I'm misinterpretting this, but is the Command Pattern like the Observer pattern or like using Delegates? Like what's the difference between this and having the ElectronicDevice interface (I guess it would have to be a class to inherit from in order to use delegates/events) and saying class TV : Electronic Device { base.onTurnOn += TV.TurnOnTV; } Just curious. Thanks.
@derekbanas
@derekbanas 12 жыл бұрын
Congrats :)
@rickmonarch4552
@rickmonarch4552 6 жыл бұрын
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 :))
@josefsabl
@josefsabl 5 жыл бұрын
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?
@Lexyvil
@Lexyvil Жыл бұрын
So it's basically having a class that acts as a command rather than an object?
@suchismitagoswami5609
@suchismitagoswami5609 2 жыл бұрын
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.
@tekal85
@tekal85 7 жыл бұрын
Clear explanation thanks.
@derekbanas
@derekbanas 7 жыл бұрын
Thank you :)
@shimonbalzera8618
@shimonbalzera8618 7 жыл бұрын
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
@Basta11
@Basta11 6 жыл бұрын
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),
@Tuktukvn
@Tuktukvn 10 жыл бұрын
very helpful tutorial. Thank you very much!
@derekbanas
@derekbanas 10 жыл бұрын
Quyet Pham You're very welcome :)
@MrQwerty2524
@MrQwerty2524 6 жыл бұрын
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?
@SeaDadLife
@SeaDadLife 6 жыл бұрын
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.
@andrecelestinodev
@andrecelestinodev 7 жыл бұрын
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?
@Joske369
@Joske369 11 жыл бұрын
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
@ramkumarnj7617
@ramkumarnj7617 7 жыл бұрын
Great Video. Simple and very effective!
@derekbanas
@derekbanas 7 жыл бұрын
Thank you very much :)
@derekbanas
@derekbanas 11 жыл бұрын
Thank you :) Yes a stack would be quicker
@sheentoosi9642
@sheentoosi9642 6 жыл бұрын
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
@pablobello8372
@pablobello8372 10 жыл бұрын
Simply, but great explanation. Thanks a lot ;)
@tikarobinson9335
@tikarobinson9335 9 жыл бұрын
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.?
@GilbertAppiah
@GilbertAppiah 5 жыл бұрын
I am not sure but I think this is probably one of the most used patterns in a microservices environment where you have to make interprocess communication.
@derekbanas
@derekbanas 11 жыл бұрын
Thank you :)
@DellAnderson
@DellAnderson 10 жыл бұрын
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?
@Brax1982
@Brax1982 9 жыл бұрын
***** OOP is not bound to our real-world models and logic.
@jacqueterrell8446
@jacqueterrell8446 7 жыл бұрын
Dell Anderson 😬
@pedroreisbr
@pedroreisbr 3 жыл бұрын
Excelent class, thank you!
@marwanjabbour3739
@marwanjabbour3739 3 жыл бұрын
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.
@1b0y16
@1b0y16 6 жыл бұрын
I did the same in pascal, and actually works the way that was expected. Well done sir! @Delek Banas
@jamesviago
@jamesviago 7 жыл бұрын
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
@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.
@babugi3759
@babugi3759 8 жыл бұрын
Very helpful , easy to understand, thanks Derek!
@derekbanas
@derekbanas 8 жыл бұрын
Thank you :)
@derekbanas
@derekbanas 12 жыл бұрын
Thank you :) Yes you win the award for being FIRST today!
@terushkanaidoo5125
@terushkanaidoo5125 8 жыл бұрын
your video was really helpful!! can you post the uml diagram for this example please
@GG-uz8us
@GG-uz8us 5 жыл бұрын
Would it be better if you rename the class TurnTVOn to TurnDeviceOn, etc.?
@hexrcs2641
@hexrcs2641 5 жыл бұрын
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?
@michaelbrooks6713
@michaelbrooks6713 5 жыл бұрын
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?
@migueldev53
@migueldev53 9 жыл бұрын
The names of your classes don't make sense... It should be TurnDeviceOff instead of TurnTvOff... Also you're not coding to interfaces like you originally said at the start of the video. When you create a new Command you set the Command object to itself. TurnTvOff command = new TurnTvOff(electronicDevice);.
@gabrielferrer2400
@gabrielferrer2400 7 жыл бұрын
Why was the ElectronicDevice implemented instead of being inherited?
@kickingpinay
@kickingpinay 11 жыл бұрын
now i have an idea on how to do undo:) Thanks!
@sai80080
@sai80080 Жыл бұрын
Hi, I find this same as Bridge Design pattern. Can you please explain how this is different?
@Brax1982
@Brax1982 9 жыл бұрын
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.
@raykeating3389
@raykeating3389 3 жыл бұрын
thats one funky way to do a method call
@lucian-ovidiucondescu5110
@lucian-ovidiucondescu5110 9 жыл бұрын
Great job !
@derekbanas
@derekbanas 9 жыл бұрын
Lucian-Ovidiu Condescu Thank you :)
@jinizzraeel7705
@jinizzraeel7705 9 жыл бұрын
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.
@derekbanas
@derekbanas 9 жыл бұрын
Jin Izzraeel In this situation the undo method is normally considered a requirement rather then an option.
@AlexEttelis
@AlexEttelis 12 жыл бұрын
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?
Adapter Design Pattern
12:31
Derek Banas
Рет қаралды 310 М.
Visitor Design Pattern
13:31
Derek Banas
Рет қаралды 277 М.
王子原来是假正经#艾莎
00:39
在逃的公主
Рет қаралды 16 МЛН
Ik Heb Aardbeien Gemaakt Van Kip🍓🐔😋
00:41
Cool Tool SHORTS Netherlands
Рет қаралды 9 МЛН
Strategy Design Pattern
11:32
Derek Banas
Рет қаралды 748 М.
The BEEFY mini PC - Minisforum AtomMan G7 PT
12:40
ShortCircuit
Рет қаралды 186 М.
State Design Pattern
20:51
Derek Banas
Рет қаралды 239 М.
Observer Design Pattern
22:27
Derek Banas
Рет қаралды 661 М.
Страшно отдавать ребенка в российскую школу | Разборы
17:15
Кто убил СССР: называем поименно
54:09
НО.Медиа из России
Рет қаралды 63 М.
Abstract Factory Design Pattern
13:20
Derek Banas
Рет қаралды 497 М.