@PyanovEugen The invoker class does not create objects , so by no mean a factory method. It just has collection of command collection object. It gives out command object and the client can call the execute method.
@dnfvideo , Invoker's constructor creates 4 new commands (Exit, File, Open, Print in your example) and returns it by name. Client should use invoker JUST for commands execution with specific logic (History, Query ect).
The first point of command object is to make a command a class , a object which already the Exit , File and open class is doing. That's the main meat of command pattern to make actions classes and objects to increase resuability.
Now coming to the role of invoker , it just encapsulates things , helps for look up , helps for queuing must be and lots of other things. For me its just a look up now which returns the command object.
Cont If you are looking at the invoker class yes that class is just a wrapper , a factory. The role of invoker can mean different for different people , as you said it should not return a object , i say it can. At the end of the day its returning a generic interface so how does it matter.
Thanks for the explanation.Command Patterns are generally used when you want to map user interactions with the system as commands to your system.What ever user does like click,drag,paste etc are all queued as commands to the system.Now why do we need to queue it and save its state because the user can always undo or redo his changes.To do be able to restore back the system should save its state,actions and commands.
@GHaranadhGupta In normal games programming yo would like to use the double click mouse , sing click function again and again.
One of the other use of Command pattern is Decoupling the UI ele,ments from BO functions.If you look at MVVM patterm where view intereacts with command objects who in turn invoke the BO at the back end. So the UI element btn_click_customer_add - mapped t- -- command object Add - mappend to customerbo.add method.
It's trash.
Your Invoker class is implementation of the Factory Method pattern.
Invoker should calls a command, not returns it.
PyanovEugen 1 month ago
@PyanovEugen The invoker class does not create objects , so by no mean a factory method. It just has collection of command collection object. It gives out command object and the client can call the execute method.
dnfvideo 1 month ago
@dnfvideo , Invoker's constructor creates 4 new commands (Exit, File, Open, Print in your example) and returns it by name. Client should use invoker JUST for commands execution with specific logic (History, Query ect).
Not for creation and not for returning.
PyanovEugen 1 month ago
@PyanovEugen
The first point of command object is to make a command a class , a object which already the Exit , File and open class is doing. That's the main meat of command pattern to make actions classes and objects to increase resuability.
Now coming to the role of invoker , it just encapsulates things , helps for look up , helps for queuing must be and lots of other things. For me its just a look up now which returns the command object.
dnfvideo 1 month ago
Cont If you are looking at the invoker class yes that class is just a wrapper , a factory. The role of invoker can mean different for different people , as you said it should not return a object , i say it can. At the end of the day its returning a generic interface so how does it matter.
dnfvideo 1 month ago
Thanks for the explanation.Command Patterns are generally used when you want to map user interactions with the system as commands to your system.What ever user does like click,drag,paste etc are all queued as commands to the system.Now why do we need to queue it and save its state because the user can always undo or redo his changes.To do be able to restore back the system should save its state,actions and commands.
Venkat19824 9 months ago
Nice
satya201980 1 year ago
Hey, thanks this was a great introductory vid. to the command pattern.
brinticus 1 year ago
hi, I have a doubt..... what if we have a map with key->command & value->functor...we will be able to achive the similar behavior? ???
What exactly is the use of this in game programming & are there any use of creating
object for each command as discussed in the presentation...
GHaranadhGupta 1 year ago
Comment removed
shivkoirala 1 year ago
@GHaranadhGupta In normal games programming yo would like to use the double click mouse , sing click function again and again.
One of the other use of Command pattern is Decoupling the UI ele,ments from BO functions.If you look at MVVM patterm where view intereacts with command objects who in turn invoke the BO at the back end. So the UI element btn_click_customer_add - mapped t- -- command object Add - mappend to customerbo.add method.
View - Command Object - View model - Model
shivkoirala 1 year ago
In factory (creational) design patterns also we are doing the same that without altering the main structure we are altering the app.
Then what is the difference ?
zerotoinfinite2006 1 year ago
@zerotoinfinite2006 Factory could be used in place of the invoker, not the command pattern as a whole.
PokerVertigo 1 year ago
awesome... really helpful for me for my final exams.
pathum
pathumathukorala 2 years ago
Its good stuff!! cool keep putting more, wil be helpful to all.
Thanks
Ranga
kishorranga 2 years ago