6

I want to learn more about event driven programming. Especially where and why I would consider using events. What resources/books should I consider reading to this end? (note: I'm indifferent to language. )

4 Answers 4

6

Other than Jalayn's excellent answer I'd like to add:

Consider learning the Observer pattern

It is a Design Pattern used to implement event handling. If your programming language doesn't have first class support on delegates and events (see in Java how it solves with event handling in AWT and Swing) then you'll be implementing it using this pattern instead.

Note that Java has an Observer/Observable available in it's class library, but it is surprisingly simple to implement these yourself. In C# there are the IObserver/IObservable (that has some LINQ capabilities through Rx), but you can use delegates and events as well for the same purpose.

2
  • +1 Forgot the one I've just used yesterday! Also it is much easier to start with this than to start with the whole Swing API if one does not know it beforehand.
    – Jalayn
    Jan 24, 2012 at 9:27
  • @Jalayn: Yes, I can relate to that. By writing an observer/observable thing by myself on some other thing I just magically started to understand the Swing API. When I got into C# programming later, a friend told me that event handling is just an application of the Observer pattern and it all just fell into place with a big "A-HA" realization.
    – Spoike
    Jan 24, 2012 at 9:37
4

.NET/C#

If you're indifferent to languages, you may try it in C# (Visual Studio Express C# is free). C# has specific event and delegate keywords for event-drive programming, and it is quite easy to grasp the idea. It starts with how event listening works, and ends with how to write your own events. There is also an interesting, but a bit further advanced article, on how to implement event-based asynchronous patterns here.

Now, there is an MSDN tutorial to start you up with the basic idea.

Java/Swing

If you want to try it in Java, you may, while programming a Swing application. There is also an Oracle tutorial on that subject, more specifically the intro. Edit: check out @Spoike's answer about the Observable pattern.

Javascript/JQuery

It is more specific to how JQuery's handles events, but you may find Benson Wong's tutorial helpful. Also, you just need to download JQuery, and you're ready to try.

1
  • 1
    I'd add Objective C/Cocoa to that list if you are on a Mac
    – user28988
    Jan 24, 2012 at 17:20
1

Consider this an addendum to the real answers. But you could look into hardware interrupts on the hardware platform of your choice. Say, on an Arduino or some such micro-controller.

These are what drive event-driven programming. Higher level programmers don't usually interface with them directly, but it's good to know about the underlying hardware.

0

Though i wrote in a different context - here is a best compilation of resources to your query: https://softwareengineering.stackexchange.com/questions/82462/what-is-the-architecture-model-of-an-android-application/131352#131352

Basically, learn various patterns from POSA and related literature from the same author.

Another good resource is here.

Also, if you are in C, consider using libevent. It shows how good scalability is achievable using such constructs.

Not the answer you're looking for? Browse other questions tagged or ask your own question.