Lecture 13 Callbacks Singletons and Wrappers

Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development (3rd Edition)

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
Copyright W. Howden 1 Lecture 14: Callbacks, Singletons and Wrappers
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copyright W. Howden 2 Callback Pattern • Context: controlling entity A calls/uses controlled entity B • Problem: – B can have no control over A – How can B initiate something that is under the control of A without taking control of A? • Solution: A gives B a pointer to one of its functions to call, or an object to “execute”, when the situation occurs
Background image of page 2
Copyright W. Howden 3 Callback Objects • Controller A will call a method B.b(a) in controllee B with an object a • a must have an expected method a.callback() that is known to B and which will be called by B when the callback situation arises • A must know the name of the method B.b() in B to call
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copyright W. Howden 4 Callbacks and MV Separation • Model View separation architecture(discussed in architecture lecture) – separation facilitates change of “look and feel” where Model is retained but View changed – controller is view, controllee is model – view posts callback object with model by calling appropriate method in model – callback object must have expected callback method
Background image of page 4
Copyright W. Howden 5 DS Callback Example • Frequent Datee Feature – normally GUI will call getADate() in DL when user indicates this user option – getADate() will return date information which GUI will display – if the found date has been dated many times, we want DL to display a GUI message (i.e. execute something in the GUI) – GUI registers a FrequentDatee call back object w
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copyright W. Howden 6
Background image of page 6
Copyright W. Howden 7 Event Delegation and Callbacks Components and events, e.g. button b Options i) if b is pushed, b’s special response method is called ii) other code tells b what to do when button is pushed. “Register” a callback (actionListener) object x with b by executing b.addActionListener(x) - Callback pattern? sort of
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Copyright W. Howden 8 Related Patterns • Can be used for CallBack – Publisher/Subscriber • General pattern – Observer/Observable • Supported by classes in Java library
Background image of page 8
Copyright W. Howden 9 Publisher-Subscriber • Special Event Manager object • Objects interested in an event, register with event manager • Objects who recognize event, publish occurrence of event with event manager • Event manager informs subscribers – Expected to have a specific method that will be called
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 Observer/Observable • Observers register with Observable • Observable recognizes event and calls specified method in observer • Java Observer
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 33

Lecture 13 Callbacks Singletons and Wrappers - Lecture 14:...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online