Observer Please Snarf the Code for Today’s Class..

Slides:



Advertisements
Similar presentations
Request Management Mirror-. A random three day sample of Incidents revealed that about 86% of the registered Incidents were legitimate Requests Many other.
Advertisements

Patterns of Interaction 2: Publish-Subscribe CS 5010 Program Design Paradigms "Bootcamp" Lesson 11.6 © Mitchell Wand, This work is licensed under.
2-May-15 GUI Design. 2 HMI design There are entire college courses taught on HMI (Human-Machine Interface) design This is just a very brief presentation.
Winter 2007ACS-3913 Ron McFadyen1 Also known as publish/subscribe The essence of this pattern is that one or more objects (called observers or listeners)
The Observer Pattern SE-2811 Dr. Mark L. Hornick 1.
Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
Chapter 2: The Observer Pattern. Consider the Following Application Application specification Humidity Temperature Pressure Weather Station Weather Data.
Creating and Speaking from a Presentation Steven Reid 1.
Obstacles to Effective Listening
March Ron McFadyen1 Design Patterns In software engineering, a design pattern is a generally repeatable solution to a commonly-occurring problem.
Patterns – Day 13 Responsibility Read chapters 6-11 of Metsker. If you have not given me an electronic copy of your (past) presentation, please do so.
Spring 2010ACS-3913 Ron McFadyen1 Weather Station Page 39+ In this application, weather station devices supply data to a weather data object. As the data.
Reza Gorgan Mohammadi AmirKabir University of Technology, Department of Computer Engineering & Information Technology Advanced design.
Observer Pattern Fall 2005 OOPD John Anthony. What is a Pattern? “Each pattern describes a problem which occurs over and over again in our environment,
BehavioralCmpE196G1 Behavioral Patterns Chain of Responsibility (requests through a chain of candidates) Command (encapsulates a request) Interpreter (grammar.
March Ron McFadyen1 Design Patterns In software engineering, a design pattern is a generally repeatable solution to a commonly-occurring problem.
Graphical User Interface (GUI) Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Oct Ron McFadyen1 Collaborations Collaboration : an arrangement of classes, links, roles in a context to implement some behaviour. Useful for.
Winter 2007ACS-3913 Ron McFadyen1 Observer Pattern Problem: There are many objects (observers / subscribers) needing to know of the state changes, or events,
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Object-Oriented Analysis and Design
1 Observer Design Pattern By Eric Perret Pages in Applying UML and Patterns.
Listening Skills. Complete all readings and work before class Have a good attitude about the class and the teacher before you get into the classroom Be.
Generics, Proxy, and The Compile Time Type Checking Debate You are either with us or against us. Please snarf the code for today’s class.
DESIGN PATTENS - OBSERVER PATTERN
Design Patterns.
02 - Behavioral Design Patterns – 2 Moshe Fresko Bar-Ilan University תשס"ח 2008.
Ants. The Project A different (but very common) kind of programming competition Different skills But also fun, and not too much work.
Design Patterns Part two. Structural Patterns Concerned with how classes and objects are composed to form larger structures Concerned with how classes.
Have you implemented “Number Talks” in your classroom? What are the pros? What are the cons? Any suggestions?????
CSC 313 – Advanced Programming Topics. Design Pattern Intent  Each design pattern is a tool  Like all tools, have reason for being.
CS 210 Introduction to Design Patterns September 7 th, 2006.
Observer Behavioral Pattern. Intent Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified.
Programming in C# Observer Design Pattern
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
CS 350 – Software Design The Observer Pattern – Chapter 18 Let’s expand the case study to include new features: Sending a welcome letter to new customers.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
Please snarf the code for today’s class. Then think about the famous 8-Queen’s Puzzle. The question is: is there a way to arrange 8 queens on a (8x8) chessboard.
(1) Unit Testing and Test Planning CS2110: SW Development Methods These slides design for use in lab. They supplement more complete slides used in lecture.
Model View Controller A Pattern that Many People Think They Understand, But Has A Couple Meanings.
Storing Data. A Note About Creating Games Why do you want to store data? 1.Data files 2.Configuration files.
Chapter 18 The Observer Pattern Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh.
Behavioural Design Patterns Quote du jour: ECE450S – Software Engineering II I have not failed. I've just found 10,000 ways that won't work. - Thomas Edison.
Patterns of Interaction 2: Publish-Subscribe CS 5010 Program Design Paradigms "Bootcamp" Lesson © Mitchell Wand, This work is licensed.
Behavioral Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
The Observer Pattern.
CS 210 Review October 3, 2006.
The Last Lecture CS 5010 Program Design Paradigms "Bootcamp" Lesson © Mitchell Wand, This work is licensed under a Creative Commons Attribution-NonCommercial.
L10: Model-View-Controller General application structure. User Interface: Role, Requirements, Problems Design patterns: Model – View – Controller, Observer/Observable.
Unit Testing & Code Coverage Please download and install EclEmma (link in resources section…I recommend Option 2) Also snarf the junit code for today’s.
Observer / Observable COMP 401 Fall 2014 Lecture 14 10/7/2014.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
Slide design: Dr. Mark L. Hornick
Observer Pattern Keeping An Eye on Things Need to introduce observer pattern formally first, include book definition & design principle Keeping An Eye.
Event-driven design will set you free The Observer Pattern 1.
OBSERVER PATTERN OBSERVER PATTERN Presented By Presented By Ajeet Tripathi ISE
The Observer Design Pattern Author :Erich Gamma, et al. Source :Elements of Reusable Object-Oriented Software Speaker : Chiao-Ping Chang Advisor : Ku-Yaw.
Observer Design Pattern
Observer Design Pattern
Patterns of Interaction 2: Publish-Subscribe
OO Design - Observer Pattern
Patterns of Interaction 2: Publish-Subscribe
Introduction to Behavioral Patterns (1)
Observer Design Pattern
CMPE 135 Object-Oriented Analysis and Design March 21 Class Meeting
Design Patterns Lecture part 1.
8. Observer Pattern SE2811 Software Component Design
Week 6, Class 2: Observer Pattern
Software Design Lecture : 40.
Presentation transcript:

Observer Please Snarf the Code for Today’s Class.

Today you will Implement the observer pattern on some sample code Hear about a few more general issues with the observer pattern Take a look at Tivoo Part 3

The WeatherData example Go to “Head First Design Patterns Observer” in the resources section of Sakai, and read the problem description (pages 38-41) Then take a look at the WeatherData class in the code you’ve snarfed. Come to a consensus with those sitting next to you about what’s wrong with it. You should be able to find at least 2 things.

What’s wrong with the WeatherData class? (more than one may apply) 1.The class handles two things: communicating with the remote weather station and dealing with the GUI 2.WeatherData is a data class 3.Duplicated code in the measurementsChanged method 4.This code is not “closed” in the situation where new kinds of weather displays are added

What We Want Code for handling the model to be separate from code focused on displaying the data But there’s a problem: oftentimes displays need to be updated when the model changes So the model code needs to call the display code So the model code needs to know about the display code

Solution So the model code needs to call the display code So the model code needs to know about the display code The model code allows other code to register it’s interest in updates (we say it allows Observers to register themselves) Then the display code registers…this happens in the man or someplace outside of the model Whenever a change happens, the model notifies all its observers The key insight here is that although the model knows something probably receives updates, it does not care what kind of classes do that. So it is “open” to any new kind of observer

We want the classes to look like this (but keep the existing functionality)

Go ahead and submit your code via Ambient

Observer in General

Not just in GUIs Anyplace where you want notifications of what happens, but want to decouple the code that notifies from the code that acts on the notifications

Push vs. Pull “Push” – the subject passes a lot of data about what has changed to it’s observers. Makes it easier for observers. “Pull” – the subject just notifies the observers and then they query subject (or other state) to figure out how they ought to change. Allows subjects to be more generic.

Be Aware Java has built-in observer objects for you to subclass from (java.util.Observable and java.util.Observer). They take of the drudge work of implementing observers. (HFDP pg. 64) But don’t confuse the idea (pattern) of observer with Java’s implementation. Even when there’s a built in one, you’ll often want to roll your own.

Limits of Observers When you have many data objects, all of which can be observed it can get difficult to set up the appropriate observer relationships Occasionally the observer pattern can be used with data too – one part of the model is updated when another part changes. Be careful with this – you can get infinite update loops or other problems