Introduction to Event-Based Programming
Before starting my tutorials on event-based programming, you
might want to know what event-based programming is, why it is cool and how it
can help you.
What is Event-Based
Programming?
Event-Based Programming (EBP) is a technique that leverages events and
notifications as the primary means to interconnect the main parts of a
software system.
What Benefits does it
Bring?
It reduces or eliminates coupling, yielding simpler parts that can often be
developed and tested in isolation from the rest of the system. The bigger
the system, the greater the benefits.
How are Event-Based
Systems Different from Event-Driven Systems?
An
event-based system
uses events and notifications
internally
to propagate commands and changes throughout the
system. An
event-driven system responds to
externally
generated events. The internal structure of an
event-driven system may have little or nothing to do with events and
notifications. Applications that run under a GUI operating system (e.g.
Windows), are event-driven: they are essentially idle until an event occurs,
like a mouse click on a key press. In response to the event, the application
does something and then goes idle again, waiting for the next event.
Do I Need Special
Programming Languages or Tools to Develop an Event-Based System?
No. All the popular programming languages, including C#, Java, C++,
ObjectPascal and others can be used. Although event-based programs tend to
be developed in object-oriented languages, older languages such as C or even
assembly languages can be used. Fundamentally, the language must support the
notion of pointer or reference.
Are Event-Based Programs
Bigger than Traditional Ones?
Adding an event-based approach to a system doesn't make it any bigger than a
system developed in traditional OOP style (in which objects call each other
directly, through interfaces).
Can I Develop
Embedded
Event-Based Systems?
Absolutely. As proof, I recently built a complex event-based application for
Amtrak that runs on a Windows Mobile 6 handheld device. The program
interacts heavily with hardware systems, such as Bluetooth devices, laser
barcode scanners, WiFi, 3G cellular modems and magnetic stripe readers.
Because I could test most of the system components in isolation from the
hardware environment, I could run the code on a Windows Vista computer,
making development and testing much simpler.
Do you have an Online
Tutorial to introduce me to EBP?
Yes. You can find a tutorial
here. Full source code for the tutorial can be found
here.