command-pattern

Command Pattern for undo/redo in paint application

廉价感情. 提交于 2019-12-20 14:41:34
问题 I would like to implement undo/redo in a small paint application. It seems the Command Pattern fits the use nicely, but I am unsure how to best implement it. As I understand the pattern, it is necessary to include in each command: The details of the paint operation for purposes of redo (e.g. Line -> start & end points, free form line -> GeneralPath ) The state of the component prior to the change for undo. In this case, that will be a small snapshot image of the area affected by the command.

JavaFX Transition animation waiting

眉间皱痕 提交于 2019-12-19 05:08:29
问题 so quicky, I am doing program which demonstrate methods used for computer graph drawing. I need to create timeline or history of actions like ( placeVertex(x,y), moveVertex(newX,newY) etc. ) and iterate through (forward and backwards, automatically or manual) I already achieved that by using command design pattern but few of these commands are using transitions. First idea was to use Condition interface's lock, await and signal in setOnFinished between each commands but it led to gui freezing

Multiple consumers for the same message through Unity not working in MassTransit

风流意气都作罢 提交于 2019-12-19 03:09:23
问题 I'm having a lot of problems lately because of what seems to be a bug in the MassTransit.UnityIntegration package, primarily due to the fact that registration names are not being considered. For instance, if I register my classes like this: var container = new UnityContainer() .RegisterType<Consumes<Command1>.All, Handler1>("Handler1") .RegisterType<Consumes<Command1>.All, Handler3>("Handler3"); A few lines later, I use the LoadFrom extension method to get the registered consumers in the

Implementing the command pattern

谁说我不能喝 提交于 2019-12-18 14:48:28
问题 I am in the design process of an application, and I would like to use the command pattern for undo/redo purposes. I did some research into the command pattern but the only thing I don't get is: Should a command have the undo and redo methods, or should I make two separate commands, one for undo and one for redo, and call those from the main command itself? 回答1: The command object itself should implement the undo / redo functionality. The commands are generally pushed and popped from a stack

Why should I use the command design pattern while I can easily call required methods? [closed]

安稳与你 提交于 2019-12-17 23:20:17
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . Locked . This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions. I am studying the command design pattern, and I am quite confused with the way of using it. The

Command Pattern : How to pass parameters to a command?

空扰寡人 提交于 2019-12-17 17:33:25
问题 My question is related to the command pattern, where we have the following abstraction (C# code) : public interface ICommand { void Execute(); } Let's take a simple concrete command, which aims to delete an entity from our application. A Person instance, for example. I'll have a DeletePersonCommand , which implements ICommand . This command needs the Person to delete as a parameter, in order to delete it when Execute method is called. What is the best way to manage parametrized commands ? How

In C# how do I properly implement the Command Design Pattern?

本秂侑毒 提交于 2019-12-13 12:05:46
问题 I'm currently studying design patterns and I'm currently looking at the command pattern. Here is my current code: // this is the receiver class Calculator : IReceiver { int x; int y; CommandOptions command; public Calculator(int x, int y) { this.x = x; this.y = y; } public void SetAction(CommandOptions command) { this.command = command; } public int GetResult() { int result = 0; switch(this.command) { case CommandOptions.ADD: result = this.x + this.y; break; case CommandOptions.SUBTRACT:

command pattern serialization in c++

末鹿安然 提交于 2019-12-12 14:39:48
问题 I want to do the folloing in C++: create a command object serialize it (send it to another computer) deserialize execute Two cases: sender and receiver are both win 7 computers sender is *nix and receiver is win 7 I found a tutorial for searialization: http://www.functionx.com/cpp/articles/serialization.htm. Is this the way to go? In python I could do: def setAndPackCommand(self, object): outFile = StringIO.StringIO() pickledC = pickle.dump(object, outFile) # this packs object to outFile

Async method returning Task<T> with generic constraint in C#

和自甴很熟 提交于 2019-12-12 12:32:16
问题 I've implemented a command pattern in a project I'm working on. This is pretty much the current structure: public class Response { public bool Success { get; private set; } public static Response CreateErrorResponse() { return new Response { Success = false }; } } public interface ICommand<T> where T : Response { Task<T> ExecuteAsync(); } public abstract CommandBase : ICommand<T> where T: Response { protected abstract Uri BuildUrl(); protected abstract Task<T> HandleResponseAsync(); public

Mixing Command pattern, Factory pattern and templates all together …

删除回忆录丶 提交于 2019-12-12 10:19:46
问题 I already asked a similar question here, however I didn't really get the answer I wanted because my question was poorly formulated and the examples were bad. So I give it another shot, with hopefully a better explanation and better code . The code bellow has been stripped out of unnecessary details but it works . The thing is I would like to use Template Argument Deduction, if possible, to simplify the templated function call . I have a factory which creates commands. To create a command, I