什么是行动设计模式?

时间:2022-09-10 11:59:39

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.

什么是动作设计模式,我以前没有听说过它?我怀疑它与命令设计模式[*]相同,但我找不到任何资源。

3 个解决方案

#1


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.

你是对的,动作模式==命令模式。您可以在GUI设计中更频繁地听到它称为动作模式,其形式为“按下某个按钮,执行此操作”。在代码中,按钮将与某种动作对象连接。

#2


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.

我现在正在MSDN上阅读“Action / Executor Pattern”,我不同意Command和Action / Executor模式相同的前提。

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

从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:

从MSDN有关Action / Executor模式的文章:

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.

Action / Executor模式标识了将用例映射到代码的策略,从而提高了可见性和灵活性。此外,它还解决了污染实体和跳过正确使用交易的问题。

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.

差异似乎是“动作”封装了一个或多个步骤,当执行成功时,将控制委托给另一个负责知道如何将这些更改持久保存到数据库,Web服务或文件存储的对象。该操作与执行/持久化的方式分离。

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 / Executor模式的一半 - “action”似乎与“command”同义。 Action / Executor模式更进一步,描述了另一个关注点,它的职责是采取“action”或“command”生成的更改并将它们保存到某个位置。

#3


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.

动作设计模式与Command设计模式相同。 Action是一个关键实体,它自身封装信息,包括它的行为,必须对其do()方法进行哪些处理,如何撤消,等等。当应用程序或其任何组件按照Action设计模式设计时,应用程序中的Everything活动可以以动作的形式表示,每个事物都可以重做/撤消几次。例如。 excel中的宏,文本编辑器中的撤消/重做等。

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

Action类,这个设计模式中的构建块可以设计如下: -

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.

希望能帮助到你。

#1


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.

你是对的,动作模式==命令模式。您可以在GUI设计中更频繁地听到它称为动作模式,其形式为“按下某个按钮,执行此操作”。在代码中,按钮将与某种动作对象连接。

#2


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.

我现在正在MSDN上阅读“Action / Executor Pattern”,我不同意Command和Action / Executor模式相同的前提。

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

从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:

从MSDN有关Action / Executor模式的文章:

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.

Action / Executor模式标识了将用例映射到代码的策略,从而提高了可见性和灵活性。此外,它还解决了污染实体和跳过正确使用交易的问题。

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.

差异似乎是“动作”封装了一个或多个步骤,当执行成功时,将控制委托给另一个负责知道如何将这些更改持久保存到数据库,Web服务或文件存储的对象。该操作与执行/持久化的方式分离。

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 / Executor模式的一半 - “action”似乎与“command”同义。 Action / Executor模式更进一步,描述了另一个关注点,它的职责是采取“action”或“command”生成的更改并将它们保存到某个位置。

#3


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.

动作设计模式与Command设计模式相同。 Action是一个关键实体,它自身封装信息,包括它的行为,必须对其do()方法进行哪些处理,如何撤消,等等。当应用程序或其任何组件按照Action设计模式设计时,应用程序中的Everything活动可以以动作的形式表示,每个事物都可以重做/撤消几次。例如。 excel中的宏,文本编辑器中的撤消/重做等。

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

Action类,这个设计模式中的构建块可以设计如下: -

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.

希望能帮助到你。