CS 4240 Principles of SW Design

Slides:



Advertisements
Similar presentations
High Quality Code Why it matters. By Ryan Ruzich.
Advertisements

The Bridge Pattern.. Intent Decouple an abstraction from its implementation so that the two can vary independently Also known as: Handle/Body.
© Copyright 2011 John Wiley & Sons, Inc.
6/10/2015Martin Odersky, LAMP, EPFL1 Programming Language Abstractions for Semi-Structured Data Martin Odersky Sebastian Maneth Burak Emir EPFL.
Design Patterns CS is not simply about programming
© 2005 Prentice Hall8-1 Stumpf and Teague Object-Oriented Systems Analysis and Design with UML.
Jump to first page 1 System Design (Finalizing Design Specifications) Chapter 3d.
Visitor Pattern Jeff Schott CS590L Spring What is the Purpose of the Visitor Pattern ? n Represent an operation to be performed on the elements.
Visitor Matt G. Ellis. Intent Metsker: Let developers define a new operation for a hierarchy without changing the hierarchy classes. GoF: Represent an.
Object-oriented Programming Concepts
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VI Composite, Iterator, and Visitor Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
CS 4240: The OO Paradigm Revisited Readings: Chap. 1 of Design Patterns Explained OO (some review) Coupling, cohesion.
What Is a Factory Pattern?.  Factories are classes that create or construct something.  In the case of object-oriented code languages, factories construct.
CS2110: SW Development Methods Design of methods (functions) Class design – CRC cards – UML class and sequence diagrams Software Design.
CS 4240: Bridge and Abstract Factory Readings:  Chap. 10 and 11 Readings:  Chap. 10 and 11.
Design Dan Fleck CS 421 George Mason University. What is the design phase? Analysis phase describes what the system should do Analysis has provided a.
CS 350 – Software Design The Object Paradigm – Chapter 1 If you were tasked to write code to access a description of shapes that were stored in a database.
SE2811 Week 7, Class 1 Composite Pattern Applications Conceptual form Class structure Coding Example Lab Thursday: Quiz SE-2811 Slide design: Dr. Mark.
Go4 Visitor Pattern Presented By: Matt Wilson. Introduction 2  This presentation originated out of casual talk between former WMS “C++ Book Club” (defunct.
COMP 6471 Software Design Methodologies Winter 2006 Dr Greg Butler
CS 350 – Software Design The Strategy Pattern – Chapter 9 Changes to software, like other things in life, often focus on the immediate concerns and ignore.
Systems analysis and design, 6th edition Dennis, wixom, and roth
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
4/1/05F-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Packages and Components in Java and UML.
Data Structures Using C++1 Chapter 1 Software Engineering Principles and C++ Classes.
Frameworks & Patterns Use of Organized Classes. Frameworks vs Toolkits Framework Framework  Start with classes and interfaces that define a rudimentary.
....and other creepy things from John Vlissides The Visitor Pattern EXISTS! And its INTENT is to represent an operation to be performed on the elements.
Lecture 12 March 16, The Scope of a Variable What if there are two variables with the same name? –A local or block-local variable can have the same.
Factory Method Explained. Intent  Define an interface for creating an object, but let subclasses decide which class to instantiate.  Factory Method.
CS 350 – Software Design Expanding Our Horizons – Chapter 8 The traditional view of objects is that they are data with methods. Sometimes objects could.
CS 4240: Rethinking Some OOP Ideas and Terms for OOA&D Readings: Chap. 8 in Shalloway and Trott (referred to as S&T in these slides) Wikipedia on information.
CS212: Object Oriented Analysis and Design Lecture 39: Design Pattern-III.
The Visitor Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Design Patterns in Context ©SoftMoore ConsultingSlide 1.
Chapter More on Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Week 6: Software Design HNDIT Software Engineering Software Design Learning Outcomes  Understand the activities involved in the Design process.
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.
CMSC 2021 Software Development. CMSC 2022 Software Development Life Cycle Five phases: –Analysis –Design –Implementation –Testing –Maintenance.
Object- oriented Design Principles
Design Patterns (II) Lecture Three. Solution to Homework Two Used framework Used design patterns: composite and state Question: what are the differences.
The Visitor Design Pattern. What’s It All About? Allows for new operations to be defined and used on elements of an object structure with out changing.
CSCE 240 – Intro to Software Engineering Lecture 3.
GRASP – Designing Objects with Responsibilities
Dan Fleck CS 421 George Mason University
Strategy Pattern.
Basic Concepts in Software Design
Design Patterns Lecture part 2.
Conception OBJET GRASP Patterns
CS 350 – Software Design The Strategy Pattern – Chapter 9
Chapter Nine The Strategy Pattern
Behavioral Design Patterns
Copyright © by Curt Hill
Polya’s Problem Solving
Best Angular 2 interview questions and Answer that have been designed for Angular 2 programmers who are preparing online interviews on Angular 2 interviews question. Visit Website:
Object Oriented Programming
Design Pattern: Visitor
Informatics 122 Software Design II
Menu item at a restaurant
Object Oriented Practices
Introduction to Computer Science for Majors II
Review CSE116 2/21/2019 B.Ramamurthy.
Strategy Design Pattern
Object Oriented Design & Analysis
More Problem Solving.
Adding Comments.
Refactoring.
Visitor Pattern Intent
Presentation transcript:

CS 4240 Principles of SW Design The Visitor design pattern Readings: Shalloway and Trott Handout from Robert Martin’s book on website www.oodesign.com © 2010 T. Horton

The Problem You have a hierarchy of classes Need to add a new method to carry out an action Need to define this for all classes in the hierarchy Painful, ugly, harmful, bad maintenance (some good reason) to do add a method to all classes

Uncle Bob’s Example Modems! A interface: Modem (Remember modems?) A interface: Modem Classes that implement this, one for each brand or model Need a new method, say, configureForUnix() Could add it to the modem? But why not?

Encapsulate What Varies Lots of possibilities for something that “does something to a modem object” depending on the object’s type Let’s call this thing a Visitor object What’s the interface between the Modem type and the Visitor type? Modem has method: accept(someVisitor) And all that does is call: someVisitor.visit(this) This implies that Visitor interface must have version of visit() for each possible Modem type

Visitor Example Class Diagram

Visitor details again Visitor interface Has a visit(E) method for each element type E in the hierarchy of objects that can be visited Concrete classes that implement Visitor Must have version of code for every type of Element Depends on the hierarchy of elements But nice cohesion

Dual Dispatch and Polymorphism Technique known as “dual dispatch” used here Two polymorphic dispatches used First: accept() is called on some object of type E (e.g. Modem) Second: then visit() is called on some object of type Visitor (which was passed)

Think about Design Tradeoffs Two dimensions of variability here They are? Using Visitor works best if one is more stable than the other Which?

Uses of Visitor Hierarchical data structures Compilers A document structure A XML/HTML document E.g. formatting, cross-references, etc. Compilers Syntax trees E.g. Optimization