Question

What is the Action Design Pattern, I haven't heard of it before? I am suspecting it is the same as the Command Design pattern [wikipedia] but I can't find any resources on it.

Was it helpful?

Solution

You're right, action pattern == command pattern. You hear it called the action pattern more often in GUI design, in the form "on some button pressed, perform this action". In the code the button would be wired up with an action object of some kind.

OTHER TIPS

I'm reading "The Action/Executor Pattern" at MSDN right now, and I have to disagree with the premise that the Command and Action/Executor patterns are the same.

From the description of the Command Pattern at SourceMaking.com:

  • Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.
  • Promote "invocation of a method on an object" to full object status
  • An object-oriented callback

From the MSDN article about the Action/Executor pattern:

The Action/Executor pattern identifies a strategy for mapping use cases to code, allowing better visibility and agility. Also, it addresses the issues of contaminating entities and skipping over proper use of transactions.

The difference appears to be that an "action" encapsulates one or more steps, that when performed successfully delegate control to another object responsible for knowing how to persist those changes to a database, web service or file storage. The action is decoupled from how it is executed/persisted.

A "command" feels like one half of the Action/Executor pattern - the "action" seems synonymous with a "command". The Action/Executor pattern takes things one step further and describes another concern whose responsibility is to take the changes generated by the "action" or "command" and save them some place.

Action design pattern is same as Command design pattern. Action is a key entity, which encapsulates information with in itself regarding what's its behavior, what processing have to be done on its do() method, how it can be undone, and so on. When an application or any of its components is designed in accordance with Action design pattern, then Everything activity in the application can be represented in the form of action, every thing can be redone/undone several times. Eg. Macros in excel, Undo/redo in text-editors, etc.

Action class, which is a building block in this design pattern can be designed as below :-

public interface Action{
  public void do();
  public void undo();
  public void do(int iNoOfTimes);
}

public class FileCopyAction implements Action{
  private int iActionId;
  public void do(){}
  public void undo(){}
  public void do(int iNoOfItems){}
}

Hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top