Lecture 13 Callbacks Singletons and Wrappers

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

Info icon This 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
Image of page 1

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

View Full Document Right 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
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
Image of page 3

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

View Full Document Right 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
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
Image of page 5

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

View Full Document Right Arrow Icon
Copyright W. Howden 6
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
Image of page 7

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

View Full Document Right 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
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
Image of page 9

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

View Full Document Right Arrow Icon
Copyright W. Howden 10 Observer/Observable Observers register with Observable Observable recognizes event and calls specified method in observer
Image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern