动作和事件有什么区别?

发布于 2024-08-27 04:18:53 字数 27 浏览 3 评论 0原文

当用户提交消息时,这是一个操作还是事件?

When a user submits a message, is it an action or event?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最佳男配角 2024-09-03 04:18:53

用户仅提供操作(按下按钮、在对话框中进行选择等)。

这些操作[有时]会被底层框架转换为事件。从概念上讲,事件可以理解为发送到方法的[通知]“消息”,这些方法已经隐式或显式地“注册”到要通知的底层框架[针对特定类型的事件]。实际上,框架仅使用适当的参数调用这些方法,并且这样的调用实际上是一个事件。

事件一词也用于指定特定类型的事件。例如,提到给定编辑框或其他 UI 元素的“更改”事件或“提交”事件。从这个意义上说,事件不是调用底层方法的机会的特定实例,而是保证调用该方法的一组通用条件。

因此,用户并没有真正按照问题中的措辞“提交消息”,他/她对各种 UI 元素采取一些操作,并且这些操作[可能]导致框架检测到这一事实特定的事件类型(或几种)。然后,框架查找当前注册了哪些方法来接收相应的通知,然后框架调用这些方法,传递适当的参数(构成供该方法使用的某种“消息”)。

该模型背后的主要思想是让应用程序级别提供处理事件的特定逻辑,而不用担心跟踪系统和用户的每一个“动作”。该框架执行此操作,并且可以信任该框架会通知相关事件处理程序特定的用户操作(或系统条件,例如计时器达到其设定时间,正在接收网络数据包等)是否需要此类通知。

A user only provides actions (pressing on buttons, making selections in dialogs etc.)

These actions get [sometimes] converted into events by the underlying framework. Events can be understood, conceptually, as [notification] "messages" sent to methods which have, implicitly or explicitly, "registered" with the underlying framework to be notified [for a specific type of event]. In reality the framework merely invoke these methods with the appropriate arguments, and such an invocation is effectively an event.

The word event is also used to designate a particular type of events. For example one speaks of the "Change" event or "Submit" event of a given edit box or other UI element. In this sense the event is not a particular instance of an opportunity for the underlying method to be called, but rather the generic set of conditions which warrant the method to be invoked.

The user therefore doesn't really "submit a message" as phrased in the question, he/she takes some actions upon various UI elements, and these action [may] result in the fact that the framework detects a particular event type (or several). The framework then looks-up which methods are currently registered to receive the corresponding notifications, and the framework then invokes these methods, passing the proper arguments (which constitute a "message" of sorts for use by the method).

The main idea behind this model is for the application-level to provide the specific logic to handle events but not worry about following the system and user's every "move". The framework does this, and can be trusted to notify the relevant event handlers would a particular user action (or system condition such as a timer reaching its set time, a network packet being received etc. etc.) warrant such notification.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文