Lesson 1 - Introduction
Lesson 1 - Introduction
Programming
Event-Driven Programming
Definition
An event is a notification that something specific has occurred, such
as a mouse click on a graphical button.
Definition
The event handler is a segment of code that is executed in response
to an event.
Events are user actions such as key
press, clicks, mouse movements,
etc., or some occurrence such as
system generated notifications.
Applications need to respond to
events when they occur. For
example, interrupts. Events are used
for inter-process communication.
Using Delegates with Events
The events are declared and raised in a class and
associated with the event handlers using delegates
within the same class or some other class. The class
containing the event is used to publish the event. This
is called the publisher class. Some other class that
accepts this event is called the subscriber class.
Events use the publisher-subscriber model.
A publisher is an object that contains the
definition of the event and the delegate. The
event-delegate association is also defined in
this object. A publisher class object invokes
the event and it is notified to other objects.
A subscriber is an object that accepts the
event and provides an event handler. The
delegate in the publisher class invokes the
method (event handler) of the subscriber
class.
Examples
Embedded applications:
cell phones
car engines
airplanes
Computation as
interaction
[Stein, 1998]:
Computation is a community of persistent entities coupled
together by their ongoing interactive behavior . . .
Beginning and end, when present, are special cases that can
often be ignored.
Imperative and Event-Driven Paradigms Contrasted
Event Sources
Example:
human,
robot sensors,
engine sensors
Event Properties
View: output.
Ex: Tic-Tac-Toe Model
class
Event Handling in C#
All C# event handlers have the same protocol, the return type is void and the
two parameters are of types object and EventArgs
Event Handling in C#
plain.CheckedChanged +=
new EventHandler (rb_CheckedChanged);
Summary