command-pattern

Command Pattern vs. Visitor Pattern

て烟熏妆下的殇ゞ 提交于 2019-12-07 00:37:06
问题 Is it generally acceptable to allow a Visitor to modify state of the Receiver, or should that be a Command pattern instead? 回答1: The purpose of the visitor pattern is to allow new operations to be added to a class heirarchy without modification to that heirarchy. I've never seen anyone suggesting that only read-only operations are acceptable. The only limitation is that the added operations should only use the public interface of the class heirarchy. 回答2: I don't think you can make a blanket

MVC and command pattern

六眼飞鱼酱① 提交于 2019-12-06 05:31:19
问题 Ok, this is kinda dumb. I'm trying to wrap my head around the use of the MVC and Command Patterns. The questions basically concern where to place code. In the MVC pattern, where are the Commands instantiated? Are they created by the Controller, or are they contained fully in the Model or neither. BTW, Should one be using the Command pattern if there is no need of undo/redo. Regards 回答1: While there are many variations based on the needs/complexity of an application, you typically find them

Command Pattern vs. Visitor Pattern

ぐ巨炮叔叔 提交于 2019-12-05 04:27:31
Is it generally acceptable to allow a Visitor to modify state of the Receiver, or should that be a Command pattern instead? The purpose of the visitor pattern is to allow new operations to be added to a class heirarchy without modification to that heirarchy. I've never seen anyone suggesting that only read-only operations are acceptable. The only limitation is that the added operations should only use the public interface of the class heirarchy. I don't think you can make a blanket statement whether it's good or bad to modify state of anything. I would think it's ok to modify the states as

How to share the same context with different threads in multi-Command Pattern in C#?

烈酒焚心 提交于 2019-12-05 02:31:24
There is an extended implementation of command pattern to support multi-commands (groups) in C#: var ctx= //the context object I am sharing... var commandGroup1 = new MultiItemCommand(ctx, new List<ICommand> { new Command1(ctx), new Command2(ctx) }); var commandGroup2 = new MultiItemCommand(ctx, new List<ICommand> { new Command3(ctx), new Command4(ctx) }); var groups = new MultiCommand(new List<ICommand> { commandGroup1 , commandGroup2 }, null); Now , the execution is like: groups.Execute(); I am sharing the same context (ctx) object. The execution plan of the web app needs to separate

Dependency Injection when using the Command Pattern

回眸只為那壹抹淺笑 提交于 2019-12-05 00:03:50
I'm using the Command Pattern for the first time. I'm a little unsure how I should handle dependencies. In the code below, we dispatch a CreateProductCommand which is then queued to be executed at a later time. The command encapsulates all the information it needs to execute. In this case it is likely we will need to access a data store of some type to create the product. My question is, how do I inject this dependency into the command so that it can execute? public interface ICommand { void Execute(); } public class CreateProductCommand : ICommand { private string productName; public

How do I implement a simple undo/redo for actions in java?

家住魔仙堡 提交于 2019-12-04 17:31:45
问题 I've created an XML editor and I'm stuck at the last phase: adding undo/redo functionality. I've only got to add undo/redo for when users add elements, attributes, or text to the JTree. I'm still quite new at this but in school today I attempted (unsuccessfully) to create two stack object []'s called undo and redo and to add the actions performed into them. FOr instance, I have: Action AddElement() { // some code public void actionPerformed(ActionEvent e) { performElementAction(); } } the

MVC and command pattern

主宰稳场 提交于 2019-12-04 10:45:28
Ok, this is kinda dumb. I'm trying to wrap my head around the use of the MVC and Command Patterns. The questions basically concern where to place code. In the MVC pattern, where are the Commands instantiated? Are they created by the Controller, or are they contained fully in the Model or neither. BTW, Should one be using the Command pattern if there is no need of undo/redo. Regards While there are many variations based on the needs/complexity of an application, you typically find them implemented in the Controller. Here is a great article on using the Command pattern in an MVC architecture. I

Why use the command pattern in GWT (or any web app)?

谁都会走 提交于 2019-12-04 10:40:42
问题 According to this video here [@ 7:50] Google is recommending the use of the Command pattern on top of its request handling API. There is also a helpful looking project gwt-dispatch that implements that pattern. According to gwt-dispatch documentation I need to create four classes for each command: an action (e.g. command) a result (e.g. response) an action handler a module Assume my service API has 100 methods across 8 BSOs, can somebody explain to me why I want to create nearly 400 new

WPF: MVVM: Command vs CallMethodAction?

浪子不回头ぞ 提交于 2019-12-04 03:54:43
问题 I'm learning the MVVM pattern with a new(small) project, and I've one question about the way to invoke actions on our controller: I saw many tutorial where they were telling us to use Command, implying to declare a RelayCommand, initialize it and create the action called by the RelayCommand. In the other side, I've a colleague which said me that I can use the CallMethodAction with a trigger: <i:Interaction.Triggers> <i:EventTrigger> <ei:CallMethodAction MethodName="Init" TargetObject="

using the command and factory design patterns for executing queued jobs

泄露秘密 提交于 2019-12-03 20:15:45
问题 I have a list of jobs queued in the database which I need to read from database and execute them in parallel using threading and I have a list of command classes to execute each of those jobs all implementing a common interface (command pattern). but when I retrieve the pending jobs from the database, I will need to instantiate the right command object for each job something like this (in a factory class) ICommand command; switch (jobCode) { case "A": command = new CommandA(); break; case "B"