Command Pattern - Design Patterns

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

Use code KYLE for an additional $50

The command pattern is probably my favorite design pattern, because of all the fun things you can do with it. The idea of the command pattern is to create an abstraction between the operations an object can do, its commands, and the actual commands themselves. This makes it really easy to combine together or chain different commands without having to change the code. The program can dynamically chain and combine these actions. The best part is since each command is its own object you can easily implement and undo function for each command and make a set of undo-able actions.

📚 Materials/References:

🧠 Concepts Covered:

- What the command pattern is
- Why the command pattern is important
- How to implement the command pattern in JavaScript
- When to use the command pattern

🌎 Find Me Here:

#CommandPattern #WDS #DesignPatterns
Рекомендации по теме
Комментарии
Автор

This pattern makes even more sense in a static typed language where you can create a "Command" interface, which the Commands extend.

JokersLaught
Автор

Ideally "undo" shouldn't take any parameters and the command class should be immutable, storing the "currentValue" itself, so undo is assured to reverse the original command.

Greedygoblingames
Автор

The clearest and illustrative way explaining design pattern I ever get.

xyzhang
Автор

Glad to see some sponsorship on your videos. These are hands down the best js videos ive ever seen, and you deserve to be compensated for them. Thanks!

laysdong
Автор

Love your consistency!!! I gotta ring that bell to be notified when you post new videos :)

linhdo
Автор

Thank you so much for showing this example without complicating it with threading as some examples do. This was very clearly explained!!

heavyraindrops
Автор

I get how the pattern is implemented, but I'm not sure what problem does it solve. The "why" is more important than "what" or "how".

GaneshSatputeAtPlus
Автор

Couldn't have made this concept anymore simple and easy to consume, great job!

sonayr
Автор

Lovely! I've been around for a bit and it reminds me of the postFix notation in Forth, SmallTalk and a few other languages. What it comes down to is that you first push values (operands) onto a stack followed by the operator. So rather "3 5 +" then "3 + 5". In this example, "3 5 +" pushes the numbers onto the stack because they are numbers/operands. The "+" is recognized as an operator. and It'll add the 2 numbers by pulling them from the stack and pushing the result "5".
I am not sure if this was actually implemented in SmallTalk but you can easily manage history by adding markers to the stack in the same way as try/catch (and a few other "GOTO's in disguise") work.
Stacks are just arrays of objects and can be easily inplemented in Javascript ;-)

Anyway: thanks for all your efforts to share you knowledge in a very accessible way!
Ed

montebont
Автор

This is randomly getting recommended now!

deansprivatearchive
Автор

Thanks a lot Kyle, this is the first time I've seen this.

JoeWong
Автор

But in that way maybe you eventually have to pay extra attention for the undo part ? Because if a function is sort of irreversable (i mean, in case you can't track of the original value just by doing the other way around) e.g in the typical case user put 0 as a multiplier. And because the undo part is coded in a bit of hard coded way, so there could be many cases you can't come back to the initial value and then you have to add extra code to fix it although it doesn't necessarily hurt the worth of pattern itself. Just a thought.

bordertone_
Автор

Hi I love you video the way u built it. Thks for all u efforts take to explain the concept.

vivekborade
Автор

This is sick! I definitely need to practice it as it's still really confusing, but you did a great job explaining it and how it could be used sort of like Lego or higher order functions (I think that's where you have a function that calls other functions right? :P ) Still pretty new. Thanks for your great videos.

randymartin
Автор

this was so clear and easy to understand! doing a great job!

ProgrammingwithPeter
Автор

Nice and clean explaination of the command pattern.

blokche_dev
Автор

Hi Kyle, thank you for the content!! I noticed that you didn't build a base command class that could be extended to child commands. Would you suggest implementing a base command with a value and execute and undo methods?

corteznumber
Автор

For doing save and exit i find this kinda overengineered. You could also just call Save () and then Exit() inside the Save&Exit and you would not have to duplicate anything. Also for Save and Exit.. Providing an undo is not really something that's is useful and should be done

pinguincoder
Автор

this was really clear and helpful : ) ! thank you !

MrMarkgyuro
Автор

You explained this perfectly. Thank you

heavencanceller