command-pattern

Command Pattern seems needlessly complex (what am I failing to understand?)

…衆ロ難τιáo~ 提交于 2019-11-28 02:49:33
问题 I've read up on the Command Pattern, and I think I'm missing something. The Command object exists to abstract away the details of the Receiver object. It seems to me that we could simply stop here, and hold references to Command objects to execute the appropriate method at the appropriate time. Why, then, is the Invoker needed? What advantage does this additional indirection provide? We've already hidden the details of the Receiver behind the Command, what's the motivation for the Command to

How does the Command pattern decouple the sender from the receiver?

為{幸葍}努か 提交于 2019-11-27 18:52:51
问题 The Command pattern has an IReceiver interface with few methods and corresponding to each method there are concrete Command objects (implementing an interface ICommand with execute() method). I have read that the client knows about the concrete receiver and concrete command and it is usually the client setting up the receiver object in the concrete command object. Then why it is said it decouples the sender and the receiver? When the client already knows the concrete receiver then I feel this

command pattern returning status

梦想与她 提交于 2019-11-27 11:55:47
问题 Once I had a discussion about design, relative to the command pattern. My peer stated that a command object should not return the status (successful, unsuccessful, and why) after the .execute() method is called. The reason is that you should not be concerned if the command gets executed or not, because the command must contain no state. You must however check after the invocation if the command had the expected effect. Another point he argued was that on the Gang of Four, the command pattern

Using a strategy pattern and a command pattern

夙愿已清 提交于 2019-11-27 09:58:50
Both design patterns encapsulate an algorithm and decouple implementation details from their calling classes. The only difference I can discern is that the Strategy pattern takes in parameters for execution, while the Command pattern doesn't. It seems to me that the command pattern requires all information for execution to be available when it is created, and it is able to delay its calling (perhaps as part of a script). What determinations guide whether to use one pattern or the other? I'm including an encapsulation hierarchy table of several of the GoF design patterns to help explain the

Callback/Command vs EventListener/Observer Pattern

喜欢而已 提交于 2019-11-27 09:09:52
问题 I'm trying to design an async framework and wanted to know what people think are the pros/cons of the callback pattern vs the observer pattern. Callback pattern: //example callback public interface Callback{ public void notify(MethodResult result); } //example method public class Worker{ public void doAsyncWork(Callback callback){ //do work callback.notify(result); } } //example observer pattern public interface EventListener{ public void notify(MethodResult result); } public class Worker{

Using a strategy pattern and a command pattern

梦想与她 提交于 2019-11-27 04:02:19
问题 Both design patterns encapsulate an algorithm and decouple implementation details from their calling classes. The only difference I can discern is that the Strategy pattern takes in parameters for execution, while the Command pattern doesn't. It seems to me that the command pattern requires all information for execution to be available when it is created, and it is able to delay its calling (perhaps as part of a script). What determinations guide whether to use one pattern or the other? 回答1:

Using Command Design pattern

China☆狼群 提交于 2019-11-26 20:32:38
Can any one explain with simple example of Command Pattern. I refer in internet but i got confused. public interface Command { public void execute(); } For the most part, commands are immutable and contain instructions that encapsulate a single action that is executed on demand. You might also have a RuntimeCommand that accepts instructions upon execution, but this delves more into the Strategy or Decorator Patterns depending on the implementations. In my own opinion, I think it's very important to heed the immutable context of a command otherwise the command becomes a suggestion. For instance

Using Command Design pattern

北慕城南 提交于 2019-11-26 09:02:07
问题 Can any one explain with simple example of Command Pattern. I refer in internet but i got confused. 回答1: public interface Command { public void execute(); } For the most part, commands are immutable and contain instructions that encapsulate a single action that is executed on demand. You might also have a RuntimeCommand that accepts instructions upon execution, but this delves more into the Strategy or Decorator Patterns depending on the implementations. In my own opinion, I think it's very

Long list of if statements in Java

北慕城南 提交于 2019-11-26 00:45:52
问题 Sorry I can\'t find a question answering this, I\'m almost certain someone else has raised it before. My problem is that I\'m writing some system libraries to run embedded devices. I have commands which can be sent to these devices over radio broadcasts. This can only be done by text. inside the system libraries I have a thread which handles the commands which looks like this if (value.equals(\"A\")) { doCommandA() } else if (value.equals(\"B\")) { doCommandB() } else if etc. The problem is