• Instead of invoking a procedure directly, a component can announce one or more events (such as arrival of data or execution of an operation)
• ON <EVENT> IF <CONDITION> THEN <ACTION>
• On arrive D if D < a or D ≥ b then print ( “out of bounds”)
• Such procedures are also called triggers, actors or eventcondition-action (ECA) rules
• An advantage of event-based invocation is that it encourages reuse; a component can be introduced in a system simply by registering it for the events of that system
• A component may:
• Announce events
• Register a callback for events of other components
• Publishers of events do not know which components (subscribers) will be affected by those events
• Components cannot make assumptions about ordering of processing, or what processing will occur as a result of their events
• Programming environment tool integration
• User interfaces (Model-View-Controller)
Event-Based Style: example
• Integrating tools in a shared environment
• Editor announces it has finished editing a module Compiler registers for such announcements and automatically re-compiles module
Editor shows syntax errors reported by compiler
Advantages and Disadvantages
Strong support for reuse: plug in new component by registering it for events
Loss of control:
What components will respond to an event?
In which order will components be invoked?
Are invoked components finished?
Correctness hard to ensure: depends on context and order of invocation