Design & Implementation Notes
CSE681 - Software Modeling & Analysis

Note #8 - Events

Event handlers, Delegates, and Commands

Event driven processing is found in almost every user interface, communication subsystem, and is pervasive in the design of operating systems. A model of window event handling for the Windows operating system is shown in the diagram, below.

Conclusions:

One important design goal for event handling is to decouple event publishers from event subscribers.
  1. .Net Delegates allow the publisher to be entirely ignorant of the subscribers. It doesn't need to know how many nor their types. Subscribers need to know the publisher and its delegate types, but don't need to know any details of how the event generation is implemented.

    Because of the way Delegates are implemented, each Delegate type can hold references to functions with only one specified signature, but that function can be a member of any type.

  2. Command Pattern event handling also decouples Publisher and Subscriber, but in a slightly more flexible way than the .Net Delegate. Since the concreteCommand objects derive from command and are implemented by the Subscriber, their execute methods can hold references to functions of any signature, and the invoker can hold any mixture of concreteCommand objects needed for the application.