Event driven programming is a programming paradigm which uses events and callbacks to control the flow of execution in a program based on it’s state It differs from procedural programming#todo [Link to own page] which runs the same set of functions every time.

It is an asynchronous programming style, as when events are run are not determined inside the program. As such, it is the events that control the flow of execution, not the functions (as in the case of imperative programming).

Definitions

State

The state of the program is the current ‘snapshot’ of all the properties and variables of the program. Similarly, the state of an object/class is the current values of all it’s variables.

Event

Any change in state is defined as an event. Events are fired (activated) on a change in state. For example, if a Player changes state from Alive to Dead, an event called PlayerKilled could be fired. Callbacks link/attach to events.

Callback/Listeners

Functions that attach to events are known as callback functions (or listeners). An object/module can (and usually do) have multiple callbacks. However, a callback function must be attached/registered to an event with an event generator.

Technically a callback/listener has a function inside it known as the event handler, which handles the event. If a callback is attached to multiple events, it would have a handler per event. In most cases, the event handler and the callback mean the same thing: a function that is called in response to an event.

Examples

Exception Handling in Java

#todo

Observer Pattern

UML Class

The update function defined in the Observer pattern is synonymous to callback functions. The act of subscribing (through the use of subscribe()) is synonymous to registering an event handler.

Graphical User Interfaces (GUI) frameworks

#todo

Pros & Cons

#TODO