在不同的上下文中,术语“command”是否有不同的含义?

huangapple go评论77阅读模式
英文:

Does the term "command" have various meanings depending on the context?

问题

我是一名初级开发者,对软件工程的基础知识感到困惑。

我第一次听到“命令”这个词是在学习GoF设计模式中的命令模式时。

但我注意到命令不仅与设计模式有关,还与我不熟悉的东西有关。

我发现命令与诸如事件、命令处理程序等词语有关。
这些命令都是一样的吗?或者我的想法是对的,命令在不同的上下文中有不同的含义?

我已经谷歌了大约三天,但没有成功。
你能帮助我吗?

英文:

I'm a junior developer struggling with a very basic knowledge in the software engineering.

I heard the term command for the first time when I studied command pattern in GoF design patterns.

But I've noticed command has to do with not only design pattern, but it also has to do with something I'm not familiar.

I found command with words such as event, command handler.
Those commands are all the same? Or Is my thought right that command has various meanings in various context?

I've googled for about three days, but with no success.
Could you help me with this?

答案1

得分: 1

与这个行业中的大多数术语一样,Command 也具有重载功能。

设计模式 - 命令

这个设计模式的目的是让调用者和被调用者之间松散耦合。或者按照设计模式的术语来说,是调用者和接收者之间的松散耦合。

这是通过封装关于请求的所有信息到一个命令对象中来实现的。

事件 - 命令

在事件系统中,我们区分命令事件

  • 前者是可以被接受、处理或拒绝的请求
  • 后者是关于已处理给定命令的确认

一个命令可以生成零个、一个或多个事件。

比较

相似之处

在两种情况下,命令表示一个操作请求

  • 请执行带有以下参数的XYZ:...

不同之处

不同之处在于命令的范围

  • 事件:它仅包含数据,没有任何行为代码
  • 设计模式:它还包含代码,知道如何执行给定的操作(Execute
    • 这个设计模式的变种可以使操作变为有条件的(CanExecute
英文:

Like with the most of the terms in this industry the Command is also overloaded.

Design pattern - Command

This design pattern is all about to loosely couple the caller and the callee from each other. Or by using the design pattern's terminology the invoker and the receiver.

It is done by encapsulating all information about request into a command object.

Eventing - Command

In case of an eventing system we are differentiating Commands and Events:

  • Former are requests which can be accepted & processed or rejected
  • Latter are acknowledgments about the fact that a given command has been processed

A command can generate zero, one or multiple events.

Comparison

Similarity

In both cases the command represents an action request

  • Please perform XYZ with the following parameters: ....

Difference

The difference is the scope of a command

  • Eventing: it solely contains data without any behavioural code
  • Design pattern: it contains code as well which knows how to perform a given action (Execute)
    • There is a variant of this design pattern which makes the action conditional (CanExecute)

huangapple
  • 本文由 发表于 2023年1月8日 23:09:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/75048859.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定