Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Action Design Pattern?

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.

like image 675
hhafez Avatar asked Dec 19 '08 11:12

hhafez


2 Answers

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.

like image 52
GaryF Avatar answered Oct 14 '22 16:10

GaryF


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.

like image 28
Mangu Singh Rajpurohit Avatar answered Oct 14 '22 14:10

Mangu Singh Rajpurohit