1 / 14

Component-Based Software Engineering

Component-Based Software Engineering. The Java Event Model Paul Krause. Problems. Pauls Pictures Pauls Documents Pauls Sums Pauls Homework. Pauls Pictures Pauls Documents Pauls Sums Pauls Homework. Pauls ToDo Lists. Lecture 4 - Interfaces and Events. Contents

denisel
Download Presentation

Component-Based Software Engineering

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Component-Based Software Engineering The Java Event Model Paul Krause

  2. Problems • Pauls Pictures • Pauls Documents • Pauls Sums • Pauls Homework • Pauls Pictures • Pauls Documents • Pauls Sums • Pauls Homework • Pauls ToDo Lists

  3. Lecture 4 - Interfaces and Events Contents • Interfaces and Callbacks • Events

  4. Client • My Documents • Reports • Papers • Presentations Window Library But I need to tell you something! I’m in charge here, guys! File System Slide Shows Calls

  5. Callbacks • Callbacks are used in procedural libraries when they need to handle asynchronous events • The alternative is for the client to continuously poll the library for events • This is inefficient, especially if a large number of library components are registered with a client • But the use of callback means a client may observe “intermediate” states of a library • “Classically” a library’s operations would run to completion before returning control

  6. Client aUser Library Client installs callback Third party calls library “I need to tell you something!” “What’s happened?” “He’s changed a name!” “That’s cool” Callback returns Library returns Call Sequence Library invokes callback Callback queries library

  7. Directory Service public class Directory { public void addEntry(String name, File file) { // pre name != “” and file != null // post File file = map.get(name) } public void removeEntry(String name) { // pre name != “” // post map.get(name) = nil } public void registerNotifier(Notifier n) { // pre n != nil // post n registered, will be called on addEntry and removeEntry } }

  8. Lecture 7 - Interfaces and Events Contents • Interfaces and Callbacks • Events

  9. Events • An abstraction of Callback that is applicable to “federations” of interacting components • The firing of an event is a way of one object telling one or more other recipients that something interesting has happened • The sender fires an event • A recipient is called a listener and handles the event

  10. Register Event Listener Fire Event Java Event Model Event Source Event Object Event Listener

  11. Event Objects • Encapsulates information specific to an instance of an event • E.g. a “mouse click” event may contain: • The position of the mouse pointer • Which mouse button was clicked (and how many times) • The event object is passed as a parameter to the event notification method

  12. Event Listeners • These are objects that need to be notified when a certain event occurs • Event notifications are made through method invocations in the listening object • The event object is passed as a parameter • The event source must know which listener object(s) to call • This information is contained in an event-listener interface

  13. Event Sources • Objects that fire events • Implements methods that allow listeners to: • Register their interest in the events it generates; • Unregister their interest in the events it generates. • Multicast event delivery enables an event to be fired to a number of event-listeners

  14. EventSource EventListener EventObject source passed to addListener() removeListener() fires getSource() toString() notification(evt) registers 0..* invokes notifications in 0..* Summary

More Related