Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Event-driven programming

From Wikipedia, the free encyclopedia
Computer programming paradigm

Incomputer programming,event-driven programming is aprogramming paradigm in which theflow of the program is determined by externalevents.User interface (UI) events fromkeyboards andmice,touchpads andtouchscreens, and externalsensor inputs are common cases. Events may also be programmatically generated, such as frommessages from other programs, notifications from otherthreads, or othernetwork events.

Event-driven programming is the dominant paradigm used ingraphical user interface (GUI) applications and network servers.

In an event-driven application, there is generally anevent loop that listens for events and then triggers acallback function when one of those events is detected.

Event-driven programs can be written in anyprogramming language, although the task is easier in languages that providehigh-level abstractions.

Although they do not exactly fit the event-driven model,interrupt handling andexception handling have many similarities.

It is important to differentiate betweenevent-driven andmessage-driven (aka queue-driven) paradigms: event-driven services (e.g.AWS SNS) are decoupled from their consumers, whereas message/queue-driven services (e.g.AWS SQS) are coupled with their consumers.[1]

Event loop

[edit]
Main article:Event loop

Because theevent loop that retrieves and dispatches events is common amongst applications, many programming frameworks provide an implementation of an event loop, and the application developer only needs to write the event handlers.

RPG, an early programming language fromIBM, whose 1960s design concept was similar to event-driven programming discussed above, provided a built-in mainI/O loop (known as the "program cycle") where the calculations responded in accordance with "indicators" (flags) that were set earlier in the cycle.

Event handlers

[edit]

The actual logic is contained in event handler routines. These routines handle the events to which the main program will respond. For example, a single mouse-click on a "Save" command button in aGUI program might trigger a routine to save data to adatabase. An "Exit" button might trigger a routine to exit the program. The event loop receives events from all such command buttons and otherGUI elements, dispatching the appropriate event handler routine for each button.

Event handler routines need to be bound to specific events, so the event loop can dispatch the correct routine in response to the event. ManyIDEs simplify this process by providing the programmer with an event handling template for each specific event (such as a button click), allowing the programmer to focus on writing the event-handling code.

In a sequential program, keeping track of execution order and history is normally trivial. But in an event-driven program, event handlers execute non-sequentially in response to external events. Special attention and planning is required to correctly structure the event handlers to work when called in any order.

Common uses

[edit]

Most existing GUI architectures use event-driven programming.[2] Windows has themessage loop. The Java AWT framework processes all UI changes on a single thread, called theEvent dispatching thread. Similarly, all UI updates in the Java frameworkJavaFX occur on the JavaFX Application Thread.[3]

Most network servers and frameworks such as Node.js are also event-driven.[4]

Interrupt and exception handling

[edit]
[icon]
This section is empty. You can help byadding to it.(May 2024)

See also

[edit]

References

[edit]
  1. ^Chandrasekaran, Premanand; Krishnan, Karthik; Ford, Neal; Byars, Brandon; Buijze, Allard (2022).Domain-Driven Design with Java - A Practitioner's Guide. Packt Publishing.ISBN 9781800564763.
  2. ^Samek, Miro (April 1, 2013)."Who Moved My State?".Dr. Dobb's. Retrieved2018-01-28.
  3. ^Fedortsova, Irina (June 2012)."Concurrency in JavaFX".JavaFX Documentation Home. Oracle. Retrieved4 January 2018.The JavaFX scene graph, which represents the graphical user interface of a JavaFX application, is not thread-safe and can only be accessed and modified from the UI thread also known as the JavaFX Application thread.
  4. ^Event-Driven Programming in Node.js.

External links

[edit]
Imperative
Structured
Object-oriented
Declarative
Functional
Dataflow
Logic
Domain-
specific
language

(DSL)
Concurrent,
parallel
Metaprogramming
Separation
of concerns
Comparisons/Lists
Level
Generation
Retrieved from "https://en.wikipedia.org/w/index.php?title=Event-driven_programming&oldid=1325413980"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp