command-pattern

Get result of executed method in Command Pattern

前提是你 提交于 2019-12-03 12:10:40
问题 Currently I'm trying to implement Transaction Script pattern (Exactly how Martin Fowler described by using Command Pattern) in a simple test project, everything just work fine, the problem is where I don't know how to get result(s) when specified method executed in concrete class which is inherited from ICommand interface. Let's show you some code to clarify what functionality I have. I've a simple CalculateSalaryCommand class which inherited from ICommand interface public class

Real world example of application of the command pattern

我的未来我决定 提交于 2019-12-03 11:43:43
Command pattern can be used to implement Transactional behavior (and Undo ). But I could not find an example of these by googling. I could only find some trivial examples of a lamp that is switched on or off . Where can I find a coding example (preferably in Java )of this/these behaviors implemented using the Command Pattern ? In one of our projects, we have the following requirement: Create a record in DB. Call a service to update a related record. Call another service to log a ticket. To perform this in a transactional manner, each operation is implemented as a command with undo operation.

java command pattern example with Runnable class : Is Receiver missing?

女生的网名这么多〃 提交于 2019-12-03 09:55:52
问题 From Examples of GoF Design Patterns in Java's core libraries question, it was quoted that All implementations of java.lang.Runnable are examples of Command pattern. As per my understanding of Command pattern, Client calls Invoker => Invoker calls ConcreteCommand => ConcreteCommand calls Receiver method, which implements abstract Command method. Have a look at this working example Command pattern UML diagram from this article is shown as below. Have a look at this code: public class

Command Pattern for undo/redo in paint application

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 03:45:50
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. My understanding based on that is that each command needs to be 'atomic' or self contained, with all

Difference between Strategy pattern and Command pattern

十年热恋 提交于 2019-12-03 02:03:14
问题 What is the difference between the Strategy pattern and the Command pattern? I am also looking for some examples in Java. 回答1: Typically the Command pattern is used to make an object out of what needs to be done -- to take an operation and its arguments and wrap them up in an object to be logged, held for undo, sent to a remote site, etc. There will tend to be a large number of distinct Command objects that pass through a given point in a system over time, and the Command objects will hold

java command pattern example with Runnable class : Is Receiver missing?

南笙酒味 提交于 2019-12-03 01:32:16
From Examples of GoF Design Patterns in Java's core libraries question, it was quoted that All implementations of java.lang.Runnable are examples of Command pattern. As per my understanding of Command pattern, Client calls Invoker => Invoker calls ConcreteCommand => ConcreteCommand calls Receiver method, which implements abstract Command method. Have a look at this working example Command pattern UML diagram from this article is shown as below. Have a look at this code: public class ThreadCommand{ public static void main(String args[]){ Thread t = new Thread(new MyRunnable()); t.start(); } }

How to use Command pattern by passing to it runtime params

♀尐吖头ヾ 提交于 2019-12-02 12:28:04
问题 I have functionality that I am encapsulate on diff commands using Command pattern. I am creating the command with the information and logic it need how ever I am getting some params only on runtime which I need to provide my commands for example: public class sendMessageToServerCommand implements Command { @Override public void execute(String msg){ sendToServerTheMsg(msg); } } .. Command command=new sendMessageToServerCommand(); command.execute("msg I got on runtime"); Perhaps I shouldnt use

WPF: MVVM: Command vs CallMethodAction?

戏子无情 提交于 2019-12-01 18:44:29
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="{Binding}" /> </i:EventTrigger> </i:Interaction.Triggers> For me, his approach has the advantage that I don't

ASP.NET MVC - Proper usage of View Model and Command pattern

99封情书 提交于 2019-12-01 04:37:50
问题 I've been writing ASP.NET MVC applications for some time and I found them to be a good place for using the command pattern: we represent every user request as a command - a set of input params - then this command is processed (processing includes validation and other domain logic) and the result is sent back to the user. Another thing I've been using in my applications is view models. I found them to be a more convenient way of passing data to the view than using domain objects as models or

JavaFX Transition animation waiting

主宰稳场 提交于 2019-12-01 01:44:06
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. I tryed SequentialTransition but it's no use for my problem - can't change properties dynamically