Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Observer Design Pattern: Implementing Data Observation in Java - Prof. Atif M. Memon, Study notes of Programming Languages

An introduction to the observer design pattern, a software design pattern used to observe the state of an object and update multiple displays or observers in real-time. An explanation of the pattern, its assumptions, philosophy, interfaces, and an example implementation in java. It covers the creation of a main window as the subject, registration of observers, and the sendnotify() method.

Typology: Study notes

Pre 2010

Uploaded on 02/13/2009

koofers-user-mla-3
koofers-user-mla-3 🇺🇸

10 documents

1 / 4

Toggle sidebar

Related documents


Partial preview of the text

Download Observer Design Pattern: Implementing Data Observation in Java - Prof. Atif M. Memon and more Study notes Programming Languages in PDF only on Docsity! 1 CMSC 433 – Programming Language Technologies and Paradigms Spring 2007 Observer Pattern Apr. 17, 2007 2 What is it? And an Example • The observer pattern (sometimes known as publish/subscribe) is a design pattern used to observe the state of an object. • For example, we often like to display data in more than one form at the same time and have all of the displays reflect any changes in that data. – For example, you might represent stock price changes both as a graph and as a table or list box. – Each time the price changes, we’d expect both representations to change at once without any action on our part. – In Java we can easily make use of the Observer Design Pattern to cause our program to behave in this way. 3 “The Observer Pattern Assumption” • The Observer pattern assumes that the object containing the data is separate from the objects that display the data, and that these display objects observe changes in that data. 4 The Observer Philosophy • We usually refer to the data as the Subject and each of the displays as Observers. • Each of these observers registers its interest in the data by calling a public method in the Subject. • Then, each observer has a known interface that the subject calls when the data change. 5 Observer and Subject Interfaces • Lets define some abstract interfaces. They will allow us to write any sort of class objects we want as long as they implement these interfaces, and that we can declare these objects to be of type Subject and Observer no matter what else they do. 6 An Example • The user-controlled radio- button choice changes the display in two windows: – First, changes the background color and the text string in the first panel. – Second, adds the name of the new color to the list box. 7 Lets Create the Main Window! • This main window is the Subject or data repository object. 8 More Main Window Code
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved