Added: 2 years ago
From: dnfvideo
Views: 11,123
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:

All Comments (16)

Sign In or Sign Up now to post a comment!
  • It's trash.

    Your Invoker class is implementation of the Factory Method pattern.

    Invoker should calls a command, not returns it.

  • @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).

    Not for creation and not for returning.

  • @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.

  • 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.

  • Nice

  • Hey, thanks this was a great introductory vid. to the command pattern.

  • 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...

  • Comment removed

  • @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

  • 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 Factory could be used in place of the invoker, not the command pattern as a whole.

  • awesome... really helpful for me for my final exams.

    pathum

  • Its good stuff!! cool keep putting more, wil be helpful to all.

    Thanks

    Ranga

Loading...
Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more