SlideServe
Menu
Préférences
© SlideServe · v2026

Visitor Design Pattern

marra avatar
5 diapositives · 197 Views · Jan 02, 2020

Explore the Visitor Design Pattern in C++ to efficiently add methods through static and dynamic dispatch, including single and double dispatch techniques. Learn the motivation behind this pattern, its implementation, and key concepts of data, operations, elements, and visitors.

Visitor Design Pattern - slide 1
01 / 5Visitor Design Pattern
1 / 17

Télécharger la présentation

Visitor Design Pattern
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Visitor Design Pattern When Need to Add Methods Often

  2. Double Dispatch • static dispatch - compile time selection of which version of the polymorphic function to execute • dynamic dispatch – run-time selection • single dispatch – selection based on a single object, supported in C++ using virtual functions • double dispatch – selection based on multiple objects, not directly supported by C++ but implemented using Visitor Design Pattern

  3. Visitor • separates data from operations on it by defining visitor class that implements the operations • allows to easily add the operations since they are added to visitor • participants • element– has accept() method that take visitor as argument, calls visit()method of the visitor, element passes itself to the visit() method • visitor – defines visit() with parameter corresponding to the particular concrete element • when accept()is invoked, its implementation is based on type of (concrete) element • when visit() within accept() is invoked, its implementation is based on • (concrete) type of the visitor and • (concrete) type of the element (passed as parameter to visit()) that is, the implementation depends on two objects

  4. Visitor UML Diagram

  5. Visitor Review • what is static/dynamic/single/double dispatch? How is single/double dispatch implemented in C++ • what is the motivation for Visitor Design Pattern? • what is data/operations? • what is element? visitor? • what is easier to add to the code element or visitor? • what is accept()? visit()?