Design Patterns - Command Pattern Explanation and Implementation in C++

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

►Lesson Description: In this lesson I teach you one of the most powerful behavioral design patterns, the command pattern. This pattern models objects to act as a command, and it is one of the most convenient ways to store a series of 'commands' or actions that happen throughout your program. I will show you a use case of using the pattern to store commands as a queue, and this pattern could be used to elegantly implement and undo/redo system.

00:00 What are Design patterns
00:30 Behavioral Design Patterns
1:00 Command Pattern
1:30 Command Patterns uses
1:59 Design Pattern Resources
2:50 Conceptual Understanding of command pattern
4:00 A game controller example
4:40 Utilizing inheritance for is-a relationship
5:20 Key idea of what a command does
5:50 C++ explanation of virtual
6:30 Enqueing commands in some data structure
7:40 Undo commands in our history
9:10 Starting our command pattern in C++
10:15 Creating our command class
10:45 Creating our interface member functions
11:25 A simple use case for our command pattern
12:40 Creating a Move, which is a type of Command
13:50 Showing how pure virtual functions must be implemented
15:00 Creating a character
15:45 Passing our character as an argument
17:02 Preparing our character to move
18:25 Adding some output to see what is going on
20:00 Our characters first command
20:40 Storing multiple commands in a queue
23:00 Managing lifetime of our commands with pointers
24:40 Undoing our commands
25:30 How do we know it is working?
26:00 Storing position data for our character in move
29:35 Verifying our execute and undo work
31:30 Using a different data structure to perform undo
32:12 Final code walk through
34:10 Closing

►Please like and subscribe to help the channel!
Рекомендации по теме
Комментарии
Автор

Bestest playlist i have ever seen for designe patterns, love from india ❤

SahilKhan-pfxh
Автор

Enjoyed this, do more! If you had 500+ people in a room listening to you teach you'd feel the power. Views are no different.

StevenMartinGuitar
Автор

I just found your channel and I must say the content is great! Everything really well explained. Thanks for sharing.

alrutto
Автор

Finally a video that breaks this step by step explaining every little detail, great video

h_msk
Автор

I've been slowly combing through your C++ playlists, and I've been learning so much! I like your teaching style a lot. Thanks for the great content! Excited to see the channel grow :-)

citiesinspace
Автор

After rewatching it and as an advice for anyone starting on the topic I would recommend to think about using a range for loop for running the commands, and even though smart pointers are mentioned I think considering type aliases together with the semantics of unique_ptr<Command> could be something to take into consideration. (using Commads = unique_ptr<Command> --->std::vector<Commands> instead of ) great vid once again overall

mudkiptheengineer
Автор

Another great C++ tutorial video! Thanks for sharing it.

pedrolobo
Автор

Hey Mike,
I really like your videos and the way you explain the general concepts of the different patterns, before taking a deep dive in code examples. Most video covering these kind of topics lack a conceptual overview and rely solely in "explanation by example". I also would be interested to see some approaches how to combine different pattern, because they're often used in combination. Maybe, you would be interested in making a video about this topic some day? :)

peach
Автор

hardly anybody bothers to give book references. I feel sad when i watch any good video. Its so important to acknowledge the sources of information. Thanks Mike!!

deepikagoyal
Автор

Beginner here but I believe an Invokeer was not used here?

cecilkoranteng
Автор

Mike, why compiler complained about move being created over stack and pushed over vector? Why is breaking here? 23:07

julyordinary
Автор

So by handing the Character as an argument, you essentially need different command classes for different signatures.
If you'd want to have a command queue that could handle different sorts of commands, you'd have to use variadic functions in the Command class, right?
Or storing arguments in the command I guess (like with functors) and hand them to the Move class instead of the execute function. Thats probably easier.

SinixND
Автор

30:35, the usage of words "move " and "undo " was confusing for me, but I translated in my mind as (and that is the output that I would rather see) : "move by x and y" and instead of undo : " move by -x and -y ".

georgiosdoumas
Автор

I noticed you didnt do many patterns, just to say this was helpful to me, theres a lot of videos but not loads in c++, particularly in their title

AlbertRyanstein
Автор

I really enjoy watching your videos. For this pattern, I was curious about parameters. In your Move example, the x and y positions are randomly generated in the execute method, but what if you wanted these values to be specified in the main function? Would they be pass into a Move constructor, or is there a better way to do this?

markbennett
Автор

I have a question:Is good to learn first about cpu, ram, hdd, ssd basics and then move to C++?

jeffsad
Автор

What other books are a good reference material book for C++ design patterns such as these to read more about?

Prashc
Автор

Thanks for this serie Mike. Just starting it. Ambition is to code your examples in vlang. Is it correct to say that this pattern is what’s implemented in an event loop, in SDL for instance?

bruno-zlqn
Автор

Hi, thanks, great video and nice link for the book. I didn't understood why you couldn't push "Command"'s into the vector but "Command*" was OK but maybe that is another story?

Mzkysti
Автор

Robert Nystrom's book is really great

bsdooby