“The Trouble with Observer” and “Visitor Revisited”

Slides:



Advertisements
Similar presentations
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Advertisements

Matt Klein. Decorator Pattern  Intent  Attach Additional responsibilities to an object by dynamically. Decorators provide a flexible alternative to.
GoF Sections 2.7 – 2.9 More Fun with Lexi. Lexi Document Editor Lexi tasks discussed:  Document structure  Formatting  Embellishing the user interface.
CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
SWE 4743 Strategy Patterns Richard Gesick. CSE Strategy Pattern the strategy pattern (also known as the policy pattern) is a software design.
Polymorphism From now on we will use g++!. Example (revisited) Goal: Graphics package Handle drawing of different shapes Maintain list of shapes.
Computer Science – Game DesignUC Santa Cruz Today Publish/Subscribe Design Pattern Delegates Sprite movement Particles.
CSE341: Programming Languages Lecture 26 Subtyping for OOP Dan Grossman Fall 2011.
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics.
Delegates & Events Observer and Strategy Patterns Game Design Experience Professor Jim Whitehead January 30, 2009 Creative Commons Attribution 3.0 creativecommons.org/licenses/by/3.0.
BehavioralCmpE196G1 Behavioral Patterns Chain of Responsibility (requests through a chain of candidates) Command (encapsulates a request) Interpreter (grammar.
Exam Questions Chain of Responsibility & Singleton Patterns Game Design Experience Professor Jim Whitehead February 4, 2009 Creative Commons Attribution.
GoF Sections 2.7 – 2.9 More Fun with Lexi. Lexi Document Editor Lexi tasks discussed:  Document structure  Formatting  Embellishing the user interface.
Chapter 3.4 Programming Fundamentals. 2 Data Structures Arrays – Elements are adjacent in memory (great cache consistency) – They never grow or get reallocated.
© 2006 Pearson Addison-Wesley. All rights reserved9 A-1 Chapter 9 Advanced Java Topics CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2007.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Chapter 19 Java Data Structures
(c) University of Washingtonhashing-1 CSC 143 Java Hashing Set Implementation via Hashing.
Behavioral Patterns  Behavioral patterns are patterns whose purpose is to facilitate the work of algorithmic calculations and communication between classes.
Design Patterns.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
02 - Behavioral Design Patterns – 2 Moshe Fresko Bar-Ilan University תשס"ח 2008.
15-740/ Oct. 17, 2012 Stefan Muller.  Problem: Software is buggy!  More specific problem: Want to make sure software doesn’t have bad property.
Go4 Visitor Pattern Presented By: Matt Wilson. Introduction 2  This presentation originated out of casual talk between former WMS “C++ Book Club” (defunct.
Mediator Pattern and Multiuser Protection Billy Bennett June 8 th, 2009.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
The Procedure Abstraction, Part V: Support for OOLs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in.
Lexi case study (Part 2) Presentation by Matt Deckard.
Object Oriented Software Development
CSCI-383 Object-Oriented Programming & Design Lecture 18.
CSE 143 Lecture 24 Advanced collection classes (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, , slides.
4-Oct Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept  direct mode: OK for static addresses  indirect register mode:
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.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Strategy Pattern.
CSE 332: Design Patterns Review: Design Pattern Structure A design pattern has a name –So when someone says “Adapter” you know what they mean –So you can.
Inheritance Revisited Other Issues. Multiple Inheritance Also called combination--not permitted in Java, but is used in C++ Also called combination--not.
CPS Inheritance and the Yahtzee program l In version of Yahtzee given previously, scorecard.h held information about every score-card entry, e.g.,
Behavioral Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
ISBN Object-Oriented Programming Chapter Chapter
The State Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Chapter 8 Object Design Reuse and Patterns. More Patterns Abstract Factory: Provide manufacturer independence Builder: Hide a complex creation process.
The Trouble with Observer and Visitor Revisited PH Chapter 3 (pp ) Crystal Miller 03/22/06.
CSE 332: Design Patterns (Part II) Last Time: Part I, Familiar Design Patterns We’ve looked at patterns related to course material –Singleton: share a.
CS 350 – Software Design The Decorator Pattern – Chapter 17 In this chapter we expand our e-commerce case study and learn how to use the Decorator Pattern.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
DATABASE ACCESS CONTROL IST Question Almost every PHP page needs to interact with database, does that mean sqlUsername and sqlPassword need to be.
Sections Inheritance and Abstract Classes
Where are we ? Setup Sprites Input Collision Drawing Sprites
Chapter 10 Design Patterns.
Chapter 19 Java Data Structures
Inheritance and Polymorphism
Behavioral Design Patterns
Object-Oriented Programming & Design Lecture 18 Martin van Bommel
Design Patterns with C# (and Food!)
Hashing Exercises.
Factory Method, Abstract Factory, and More
Strategy Design Pattern
Interfaces and Inheritance
Decorator Intent Also known as Wrapper Example: a Text Window
Advanced Java Topics Chapter 9
Informatics 122 Software Design II
Review: Design Pattern Structure
Polymorphism Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan.
Design pattern Lecture 9.
Context Objects Evolution of object behavior Behavioral patterns
Lecture 8 Evolution of object behavior Behavioral patterns
Design Patterns Lecture part 1.
Informatics 122 Software Design II
Refactoring.
Presentation transcript:

“The Trouble with Observer” and “Visitor Revisited” Presentation by Matt Deckard

The Trouble with Trib- I mean Observer

The Trouble with Observer Runtime redundancy every subject object duplicated in observer lots of pointers tradeoff for reuse Static redundancy inheritence in all subject and object subclasses parallel hierarchy everything multiplied by two mechanical overhead conceptual overhead

The Trouble with Observer What to do? cut down to one hierarchy but retain benefits of redundancy hmm... What if... instead of storing info, compute it on the fly tradeoff between space and time ok, as long as we don't demand info "very often" in UI example: subject changes user input UI redraw

The Trouble with Observer reduce observer object hierarchy to constant number reduce number of links too compute them on the fly too? demand for info involves traversal of Observer hierarchy so why don't we do our computation here? traverse *Subject* structure to update Subjects have flag to determine whether they need updating

The Trouble with Observer B-b-but... where do you keep the Subject's presentation code? depends on both the kind of Subject and the kind of presentation It's time to visit our friend... Visitor define Visitor class called Presenter Visit operations for each Subject class also implements traversal methods

Visitor Revisited But what about... Adding new Subject classes don't want to add new Visit operations to every Presenter use a "default" visit for abstract Subject can also put all common behavior here, have reimplemented Visits call it subclass Presenter to implement specific visit operations for new Subjects use "default" visit, but dynamically cast to new subtype must use overloading for this to work

Visitor Revisited But why not just... cast the new Presenter subclass in the new Subject's accept? much harder to add these things back into base Presenter have to change Subject hierarchy instead of Presenter hierarchy

Visitor Revisited Drawbacks lumped all functionality from ConcreteObservers into one Visitor could be fixed by delegating to Strategy objects what if Observers need to save state that's not computable on the fly? save data in separate associative data structure, keyed by Subject looks good on paper, not sure about practice