Chapter 1 - Introduction to
Event Based Programming
An event based system is one in which interactions among the
various part of the system are governed by events. Events are
occurrences of interest to which the system responds.
In computing event based systems abound. Mouse clicks, key
presses, interrupts, sensor input, messages sent and received across a
network, and database triggers are just a few examples of events. The
systems where these events occur include GUIs, database management
systems, networks and many others.
Event based programming consists of building systems that include
events. The basic tasks are deciding what events need to be
responded to, and then determining how our system will respond.
The various parts
of a system we will refer to as agents.
An agent may be an object or component within a larger system,
or it may be a standalone computing entity. The agents interact
with each other using events. There are some standard ways
in which the agents interact.
Types of Agent Interactions
Request - Response
In a Request-Response interaction, Agent A makes a request to agent B.
Agent B processes the request and sends a reply back to agent A.
The request and the response are the events. A good example
of request-response is loading a webpage. The browser requests
the page. The server receives the request and responds by sending
the page back to the browser.
Message Passing
In message passing, agent A sends a message to agent B, but agent B is
not required to respond. (Politically incorrect aside: One of the
authors' wives says that this is the basic way she communicates with
him.)
Publish Subscribe
In a publish-subscribe system, multiple agents register their interest
in particular events with a publisher. When an event occurs, the
publishers notifies all the subscribers. An RSS feed is an
example of publish-subscribe. Users subscribe to an RSS feed for
a particular topic, for
example growing tomatoes. All subscribers are sent any new
articles that appear on growing tomatoes.
Attributes of Event Based Systems
Event
basd systems all have the same general properties to varying degrees.
State based
Event based systems are state based. The system stays in a stable state
until an event occurs. Processing the event changes the state, then the
system quiets down and waits for more events.
Nondeterministic
Nondeterminism means that it is impossible to determine exactly how a
computation will proceed. Even given the same inputs the path the
computation follows may vary from run to run. All event based systems
contain varying degrees of nondeterminism.
Loose Coupling
One of the strengths of event based programming is that it allows
complex systems to be built from diverse, loosely coupled components.
The components communicate with each other via events.
Decentralized Control
Event based systems use decentralized control. The system starts up and
waits for events to occur. Each event causes changes to the system.
Even a single event can have cascading effects that propagate
throughout the system. Nobody is in charge.
Introduction
Exercises
Powerpoint Presentation