Uploader Comments (dnfvideo)
All Comments (16)
-
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.
-
Nice
-
Hey, thanks this was a great introductory vid. to the command pattern.
-
@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
It's trash.
Your Invoker class is implementation of the Factory Method pattern.
Invoker should calls a command, not returns it.
PyanovEugen 2 months 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 2 months 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 2 months 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 2 months 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 2 months ago