Visitor Pattern Jeff Schott CS590L Spring 2004. What is the Purpose of the Visitor Pattern ? n Represent an operation to be performed on the elements.

Slides:



Advertisements
Similar presentations
(A Completely Colorless Powerpoint Presentation of) The Interpreter Pattern David Witonsky.
Advertisements

INTERPRETER Main Topics What is an Interpreter. Why should we learn about them.
Introduction to Computers and Programming Lecture 9: For Loops New York University.
Iterators T.J. Niglio Computer & Systems Engineering Fall 2003 Software Design & Documentation Object Behavioral.
Design Patterns In OPM Presented by: Galia Shlezinger Instructors: Prop. Dov Dori, Dr. Iris Berger.
Trees. 2 Definition of a tree A tree is like a binary tree, except that a node may have any number of children Depending on the needs of the program,
1 Semantic Processing. 2 Contents Introduction Introduction A Simple Compiler A Simple Compiler Scanning – Theory and Practice Scanning – Theory and Practice.
1 Parts of a Loop (reminder) Every loop will always contain three main elements: –Priming: initialize your variables. –Testing: test against some known.
Façade Pattern Jeff Schott CS590L Spring What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance.
Environments and Evaluation
Trees. Definition of a tree A tree is like a binary tree, except that a node may have any number of children –Depending on the needs of the program, the.
Visitor Matt G. Ellis. Intent Metsker: Let developers define a new operation for a hierarchy without changing the hierarchy classes. GoF: Represent an.
Design Patterns Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson,Ralph Johnson and John Vlissides (The Gang of.
Software Design and Documentation Individual Presentation: Composite Pattern 9/11/03.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Chapter 5: Repetition Statements. In this chapter, you will learn about: Basic loop structures while loops Interactive while loops for loops Loop programming.
Interpreter By: Mahmoodreza Jahanseir Amirkabir University of Technology Computer Engineering Department Fall 2010.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VI Composite, Iterator, and Visitor Patterns.
1 Computer Science 340 Software Design & Testing © Ken Rodham 2003 The “Visitor” Design Pattern Source: "Design Patterns: Elements of Reusable Software"
UML class diagrams and XML schemas Karl Lieberherr UBS AG Northeastern University.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Domain Modeling (with Objects). Motivation Programming classes teach – What an object is – How to create objects What is missing – Finding/determining.
CSE 331 Software Design & Implementation Hal Perkins Winter 2013 Design Patterns Part 3 (Slides by Mike Ernst and David Notkin) 1.
The Interpreter Pattern. Defining the Interpreter Intent Given a language, define a representation for its grammar along with an interpreter that uses.
Programmatic Building of Models Just for Pretty Printing DSM October 2006 Tero Hasu Helsinki Institute for Information Technology.
Sequence Diagram & Pattern Visitor
Design Pattern Interpreter By Swathi Polusani. What is an Interpreter? The Interpreter pattern describes how to define a grammar for simple languages,
Go4 Visitor Pattern Presented By: Matt Wilson. Introduction 2  This presentation originated out of casual talk between former WMS “C++ Book Club” (defunct.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
Centralized vs. Decentralized Interpreter Pattern Visitor Pattern.
Not only mark-up languages! There are other many other grammar formalisms and tools than XML. Some of them standardized (ASN). Even XML does not always.
Stéphane Ducasse 1 Visitor.
Design Patterns – II Lecture IV. Singleton Pattern Intent – Ensure a class only has one instance, and provide a global point of access to it Motivation.
....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.
The basics of the programming process The development of programming languages to improve software development Programming languages that the average user.
11/25/2015© Hal Perkins & UW CSEH-1 CSE P 501 – Compilers Implementing ASTs (in Java) Hal Perkins Winter 2008.
A Two-Dimensional Separation of Concerns for Compiler Construction Carl (Xiaoqing) Wu, Suman Roychoudhury, Barrett R. Bryant and Jeffrey G. Gray The University.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
1 12/4/1435 h Lecture 2 Programs and Programming Languages.
1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Wei-Tek Tsai who’s.
CS212: Object Oriented Analysis and Design Lecture 39: Design Pattern-III.
The Visitor Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The Interpreter Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
The Visitor Design Pattern and Java Tree Builder
C H A P T E R T W O Linking Syntax And Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
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.
Interpreter By: Mahmoodreza Jahanseir Amirkabir University of Technology Computer Engineering Department Fall 2010.
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.
Command Pattern. Intent encapsulate a request as an object  can parameterize clients with different requests, queue or log requests, support undoable.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Chapter 10 Design Patterns.
Design Patterns Lecture part 2.
Behavioral Design Patterns
Implementing ASTs (in Java) Hal Perkins Autumn 2009
Presentation by Julie Betlach 7/02/2009
CS 4240 Principles of SW Design
Jim Fawcett CSE776 – Design Patterns Summer 2003
Design Pattern: Visitor
Informatics 122 Software Design II
Behavioral Patterns Part-I introduction UNIT-VI
Third lecture Review Visitor pattern DemeterJ 12/25/2018 SD.
Interpreter Pattern.
Third lecture Review Visitor pattern DemeterJ 2/17/2019 SD.
Strategy Design Pattern
Informatics 122 Software Design II
16. Visitors SE2811 Software Component Design
16. Visitors SE2811 Software Component Design
Visitor Pattern Intent
Presentation transcript:

Visitor Pattern Jeff Schott CS590L Spring 2004

What is the Purpose of the Visitor Pattern ? n Represent an operation to be performed on the elements of an object structure n Define a new operation without changing the classes of the elements on which it operates

When do you use the Visitor Pattern? n An object structure contains many classes of objects n Many distinct and unrelated operations on these objects - want to avoid “polluting” their classes n Classes defining the object structure rarely change, but operations change frequently

Visitor Pattern Structure

Visitor Pattern Participants n Visitor n Concrete Visitor n Element n Concrete Element n Object Structure

Visitor Pattern Collaborations

Benefits of the Visitor Pattern n Makes adding new operations easy n Gathers related operations and separates unrelated operations n Visitors can visit objects that don’t have a common parent class n Visitors can accumulate state as they visit each element

Liabilities of the Visitor Pattern n Adding new Concrete Element classes is hard n Allowing a Visitor to access the internal state of a Concrete Element breaks encapsulation

Visitor Pattern Example: Compiler Syntax Tree n Operations on Syntax Tree –Type Checking –Code Generation –Pretty Printing n Different Classes for Tree Nodes –Assignment Statements –Variables –Arithmetic Expressions

Visitor Pattern Example: Node Class Hierarchy n Distributing operations across classes is confusing n Mixing operations is confusing n Adding new operations requires recompiling all classes

Visitor Pattern Example: Visitor Class Hierarchy

Visitor Pattern Example: New Node Class Hierarchy

Visitor Pattern Implementation Issues n Double Dispatch n Who is Responsible for Traversing the Object Structure? –Object Structure –Visitor –Iterator Object

Visitor Pattern Sample Code: Element

Visitor Pattern Sample Code: Visitor

Visitor Pattern Sample Code: Concrete Elements

Visitor Pattern Sample Code: Concrete Visitor

Visitor Pattern Sample Code: Concrete Visitor (cont’d)

Visitor Pattern Sample Code: Client

Visitor Pattern Known Uses n Smalltalk-80 Compiler n IRIS Inventor Toolkit n X Consortium’s Fresco Application Toolkit n Bistro Programming Language Compiler

Visitor Pattern: Related Patterns n Composite n Interpreter n Iterator

Visitor Pattern Questions?