SlideShare a Scribd company logo
1 of 11
By Nishant S Mevawala
MSC IT(sem-2)
MSIT/11/003
Intent


Represent an operation to be performed on the elements of
an object structure. Visitor lets you define a new operation
without changing the classes of the elements on which it
operates.



The classic technique for recovering lost type information.



Do the right thing based on the type of two objects.



Double dispatch
Motivation


Consider a compiler that parses a program and represents the parsed
program as an abstract syntax tree (AST). The AST has many
different kinds of nodes, such as Assignment , Variable Reference,
and Arithmetic Expression nodes.
Motivation (con..)





Operations that one would like to perform on the AST include:
1. Checking that all variables are defined
2. Checking for variables being assigned before they are used
3. Type checking
4. Code generation
5. Pretty printing/formatting
These operations may need to treat each type of node differently
One way to do this is to define each operation in the specific node
class
Motivation (con..)


Problems with this approach:
1. Adding new operations requires changes to all of the node
classes
2.It can be confusing to have such a different set of operations in
each node class. For example, mixing type-checking code with
pretty-printing code can be hard to understand and maintain.



Another solution is to encapsulate a desired operation in a separate
object, called a visitor. The visitor object then traverses the elements
of the tree. When an tree node "accepts" the visitor, it invokes a
method on the visitor that includes the node type as an argument.
The visitor will then execute the operation for that node - the
operation that used to be in the node class.
Structure Summary
Structure


The Element hierarchy is instrumented with a “universal method
adapter”. The implementation of accept() in each Element derived
class is always the same. But – it cannot be moved to the Element
base class and inherited by all derived classes because a
reference to this in the Element class always maps to the base
type Element.
Structure (Con..)


When the polymorphic firstDispatch() method is called on an
abstract First object, the concrete type of that object is “recovered”.
When the polymorphic secondDispatch() method is called on an
abstract Second object, its concrete type is “recovered”. The
application functionality appropriate for this pair of types can now
be exercised.
Example


The Visitor pattern represents an operation to be performed on the
elements of an object structure without changing the classes on which
it operates. This pattern can be observed in the operation of a taxi
company. When a person calls a taxi company (accepting a visitor), the
company dispatches a cab to the customer. Upon entering the taxi the
customer, or Visitor, is no longer in control of his or her own
transportation, the taxi (driver) is.
Rules of thumb


The abstract syntax tree of Interpreter is a Composite (therefore
Iterator and Visitor are also applicable).



Iterator can traverse a Composite. Visitor can apply an operation over
a Composite.



The Visitor pattern is like a more powerful Command pattern because
the visitor may initiate whatever is appropriate for the kind of object
it encounters.



The Visitor pattern is the classic technique for recovering lost type
information without resorting to dynamic casts.
Thank You

More Related Content

What's hot

What's hot (20)

Abstract Factory Pattern
Abstract Factory PatternAbstract Factory Pattern
Abstract Factory Pattern
 
Bridge Design Pattern
Bridge Design PatternBridge Design Pattern
Bridge Design Pattern
 
Second review presentation
Second review presentationSecond review presentation
Second review presentation
 
Android Design Patterns
Android Design PatternsAndroid Design Patterns
Android Design Patterns
 
Flyweight pattern
Flyweight patternFlyweight pattern
Flyweight pattern
 
Design Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory PatternDesign Patterns - Abstract Factory Pattern
Design Patterns - Abstract Factory Pattern
 
Observer design pattern
Observer design patternObserver design pattern
Observer design pattern
 
Adapter pattern
Adapter patternAdapter pattern
Adapter pattern
 
Observer Software Design Pattern
Observer Software Design Pattern Observer Software Design Pattern
Observer Software Design Pattern
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Observer Pattern
Observer PatternObserver Pattern
Observer Pattern
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Adapter Pattern
Adapter PatternAdapter Pattern
Adapter Pattern
 
Facade Design Pattern
Facade Design PatternFacade Design Pattern
Facade Design Pattern
 
Observer pattern
Observer patternObserver pattern
Observer pattern
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 
Session tracking In Java
Session tracking In JavaSession tracking In Java
Session tracking In Java
 
Design Patterns & JDK Examples
Design Patterns & JDK ExamplesDesign Patterns & JDK Examples
Design Patterns & JDK Examples
 
Design pattern-presentation
Design pattern-presentationDesign pattern-presentation
Design pattern-presentation
 
Code refactoring
Code refactoringCode refactoring
Code refactoring
 

Similar to Visitor design patterns

Design Patterns
Design PatternsDesign Patterns
Design Patternssoms_1
 
ArchitectureOfAOMsWICSA3
ArchitectureOfAOMsWICSA3ArchitectureOfAOMsWICSA3
ArchitectureOfAOMsWICSA3Erdem Sahin
 
Pavel_Kravchenko_Mobile Development
Pavel_Kravchenko_Mobile DevelopmentPavel_Kravchenko_Mobile Development
Pavel_Kravchenko_Mobile DevelopmentCiklum
 
ActionScript 3.0 Fundamentals
ActionScript 3.0 FundamentalsActionScript 3.0 Fundamentals
ActionScript 3.0 FundamentalsSaurabh Narula
 
Design pattern (week 2)
Design pattern (week 2)Design pattern (week 2)
Design pattern (week 2)stanbridge
 
C questions
C questionsC questions
C questionsparm112
 
MC0083 – Object Oriented Analysis &. Design using UML - Master of Computer Sc...
MC0083 – Object Oriented Analysis &. Design using UML - Master of Computer Sc...MC0083 – Object Oriented Analysis &. Design using UML - Master of Computer Sc...
MC0083 – Object Oriented Analysis &. Design using UML - Master of Computer Sc...Aravind NC
 
CS8592 Object Oriented Analysis & Design - UNIT III
CS8592 Object Oriented Analysis & Design - UNIT III CS8592 Object Oriented Analysis & Design - UNIT III
CS8592 Object Oriented Analysis & Design - UNIT III pkaviya
 
1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answersAkash Gawali
 
Design Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur UniversityDesign Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur UniversityShubham Narkhede
 
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfAbstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfkarymadelaneyrenne19
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And AnswerJagan Mohan Bishoyi
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answerlavparmar007
 

Similar to Visitor design patterns (20)

Visual Basic User Interface -IV
Visual Basic User Interface -IVVisual Basic User Interface -IV
Visual Basic User Interface -IV
 
Ch14
Ch14Ch14
Ch14
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
ArchitectureOfAOMsWICSA3
ArchitectureOfAOMsWICSA3ArchitectureOfAOMsWICSA3
ArchitectureOfAOMsWICSA3
 
Pavel_Kravchenko_Mobile Development
Pavel_Kravchenko_Mobile DevelopmentPavel_Kravchenko_Mobile Development
Pavel_Kravchenko_Mobile Development
 
ActionScript 3.0 Fundamentals
ActionScript 3.0 FundamentalsActionScript 3.0 Fundamentals
ActionScript 3.0 Fundamentals
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Design pattern (week 2)
Design pattern (week 2)Design pattern (week 2)
Design pattern (week 2)
 
C questions
C questionsC questions
C questions
 
MC0083 – Object Oriented Analysis &. Design using UML - Master of Computer Sc...
MC0083 – Object Oriented Analysis &. Design using UML - Master of Computer Sc...MC0083 – Object Oriented Analysis &. Design using UML - Master of Computer Sc...
MC0083 – Object Oriented Analysis &. Design using UML - Master of Computer Sc...
 
CS8592 Object Oriented Analysis & Design - UNIT III
CS8592 Object Oriented Analysis & Design - UNIT III CS8592 Object Oriented Analysis & Design - UNIT III
CS8592 Object Oriented Analysis & Design - UNIT III
 
1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers
 
Classes2
Classes2Classes2
Classes2
 
Design Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur UniversityDesign Pattern Notes: Nagpur University
Design Pattern Notes: Nagpur University
 
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfAbstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
 
Tech talk
Tech talkTech talk
Tech talk
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And Answer
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Delphi qa
Delphi qaDelphi qa
Delphi qa
 

More from Nishant Mevawala

Disaster Management - Technical
Disaster Management - TechnicalDisaster Management - Technical
Disaster Management - TechnicalNishant Mevawala
 
Drying & Cleaning Plant for reprocessing of plastics
Drying & Cleaning Plantfor reprocessing of plasticsDrying & Cleaning Plantfor reprocessing of plastics
Drying & Cleaning Plant for reprocessing of plasticsNishant Mevawala
 
WebSphere Application Server
WebSphere Application ServerWebSphere Application Server
WebSphere Application ServerNishant Mevawala
 
Java Multi Thead Programming
Java Multi Thead ProgrammingJava Multi Thead Programming
Java Multi Thead ProgrammingNishant Mevawala
 
Beginning of black berry technology
Beginning of black berry technologyBeginning of black berry technology
Beginning of black berry technologyNishant Mevawala
 

More from Nishant Mevawala (6)

Adv programming languages
Adv programming languagesAdv programming languages
Adv programming languages
 
Disaster Management - Technical
Disaster Management - TechnicalDisaster Management - Technical
Disaster Management - Technical
 
Drying & Cleaning Plant for reprocessing of plastics
Drying & Cleaning Plantfor reprocessing of plasticsDrying & Cleaning Plantfor reprocessing of plastics
Drying & Cleaning Plant for reprocessing of plastics
 
WebSphere Application Server
WebSphere Application ServerWebSphere Application Server
WebSphere Application Server
 
Java Multi Thead Programming
Java Multi Thead ProgrammingJava Multi Thead Programming
Java Multi Thead Programming
 
Beginning of black berry technology
Beginning of black berry technologyBeginning of black berry technology
Beginning of black berry technology
 

Recently uploaded

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

Visitor design patterns

  • 1. By Nishant S Mevawala MSC IT(sem-2) MSIT/11/003
  • 2. Intent  Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.  The classic technique for recovering lost type information.  Do the right thing based on the type of two objects.  Double dispatch
  • 3. Motivation  Consider a compiler that parses a program and represents the parsed program as an abstract syntax tree (AST). The AST has many different kinds of nodes, such as Assignment , Variable Reference, and Arithmetic Expression nodes.
  • 4. Motivation (con..)    Operations that one would like to perform on the AST include: 1. Checking that all variables are defined 2. Checking for variables being assigned before they are used 3. Type checking 4. Code generation 5. Pretty printing/formatting These operations may need to treat each type of node differently One way to do this is to define each operation in the specific node class
  • 5. Motivation (con..)  Problems with this approach: 1. Adding new operations requires changes to all of the node classes 2.It can be confusing to have such a different set of operations in each node class. For example, mixing type-checking code with pretty-printing code can be hard to understand and maintain.  Another solution is to encapsulate a desired operation in a separate object, called a visitor. The visitor object then traverses the elements of the tree. When an tree node "accepts" the visitor, it invokes a method on the visitor that includes the node type as an argument. The visitor will then execute the operation for that node - the operation that used to be in the node class.
  • 7. Structure  The Element hierarchy is instrumented with a “universal method adapter”. The implementation of accept() in each Element derived class is always the same. But – it cannot be moved to the Element base class and inherited by all derived classes because a reference to this in the Element class always maps to the base type Element.
  • 8. Structure (Con..)  When the polymorphic firstDispatch() method is called on an abstract First object, the concrete type of that object is “recovered”. When the polymorphic secondDispatch() method is called on an abstract Second object, its concrete type is “recovered”. The application functionality appropriate for this pair of types can now be exercised.
  • 9. Example  The Visitor pattern represents an operation to be performed on the elements of an object structure without changing the classes on which it operates. This pattern can be observed in the operation of a taxi company. When a person calls a taxi company (accepting a visitor), the company dispatches a cab to the customer. Upon entering the taxi the customer, or Visitor, is no longer in control of his or her own transportation, the taxi (driver) is.
  • 10. Rules of thumb  The abstract syntax tree of Interpreter is a Composite (therefore Iterator and Visitor are also applicable).  Iterator can traverse a Composite. Visitor can apply an operation over a Composite.  The Visitor pattern is like a more powerful Command pattern because the visitor may initiate whatever is appropriate for the kind of object it encounters.  The Visitor pattern is the classic technique for recovering lost type information without resorting to dynamic casts.