Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [visitor-pattern]

The visitor design pattern is a way of separating an algorithm from an object structure on which it operates. A practical result of this separation is the ability to add new operations to existing object structures without modifying those structures.

Filter by
Sorted by
Tagged with
3 votes
1 answer
91 views

Implementing an Object type in C++

I'm currently working through the "Crafting Interpreters" book by Robert Nystrom. He uses Java to implement the visitor pattern in which the visitor functions return the Object type. C++ ...
GoZaddy's user avatar
  • 33
3 votes
3 answers
144 views

Visitor Pattern to handle human and AI responses

Let's suppose there is a method of an Inputter class that queries many questions. The Human inputter would have to answer all ...
prestokeys's user avatar
  • 1,371
3 votes
1 answer
529 views

C++: Visit Any Type Holding Other Types (`std::any`, `std::variant`, etc.)

Intro I want to visit the value held by a class, which could be of multiple types. This class is very similar to a std::any, so I will be using this in this ...
mfacchinelli's user avatar
3 votes
1 answer
2k views

visit for std::any

While solving an online excersise I have written some basic implementation for a visit function that works with std::any. The ...
Sergey Kolesnik's user avatar
0 votes
1 answer
193 views

Refactor typescript long switch case that run different code in according to property value

I have a typescript function that executes an array of actions on a given string value. This is the code: ...
chenny's user avatar
  • 183
3 votes
2 answers
164 views

Collider class using some kind of visitor pattern

I'm trying to create a Collider class which will process collisions between different classes of the same base. One restriction is that I want these classes know nothing about each other, now they ...
qloq's user avatar
  • 133
3 votes
0 answers
151 views

Replacing type-check with Visitor in Immutable Event-Sourced Aggregate

In my previous question, one of the answers mentioned that I shouldn't be changing behavior based on the Event class The whole point of classing is that you can get result without having to decide ...
Zymus's user avatar
  • 187
6 votes
0 answers
297 views

Create 'classical' visitor from lambdas

I've watched a talk by Fedor Pikus on design patterns held at CppCon 2019. Motivated by this, I wrote my own visitor implementation and some helpers which allow me to create a visitor from a couple of ...
StefanKssmr's user avatar
2 votes
0 answers
95 views

Visitor pattern, Extensible visitor for custom implementation

I'm writing my own expression tree system, just for fun, but I have a few doubts about my code. My goal here is to create an abstract layer of expressions, and allow different "languages" to ...
user avatar
4 votes
1 answer
402 views

Generic Visitor pattern library for polymorphic virtual class hierarchies

Inspired by this cppcon talk from Fedor Pikus about design patterns and some real-world need I implemented a library that allows the user to add a generic visitor pattern capabilities to class ...
lucas93's user avatar
  • 41
2 votes
0 answers
75 views

Mapping an object tree to another object tree

Programming to an interface is a design principle that enhances the flexibility of software by hiding implementation details. Consider an object tree that only exposes an interface, but you want to ...
annemartijn's user avatar
5 votes
1 answer
3k views

Calculating the average of all nodes in a Binary Search Tree using visitors

I'm required to calculate the average value of all nodes in a BST using a Visitor, I'm not sure if I did this correctly or if i could just calculate the average ...
Phalanx's user avatar
  • 51
4 votes
1 answer
720 views

Iterate through Expression Tree

I'm trying to build an iterator (enumerator) that can select specific elements in an Expression tree by traversing the tree and deferring further iteration until ...
Rhaokiel's user avatar
  • 141
1 vote
0 answers
111 views

Recursively look up directories, (a little bit) slow

I wrote some Java code to look up all files in a chosen directory (like it's showing in the Windows Explorer), and to display the results, but it seems to be slow. Can you tell me, how to speed up it? ...
CyborgBeta's user avatar
2 votes
3 answers
273 views

BST traverse as higher order function [closed]

Consider the following function to traverse a BST ...
mwal's user avatar
  • 483
7 votes
0 answers
659 views

Chaining JSON transformations with visitors

I have currently two use-cases that require JSON transformations before it can be deserialized. The first use-case requires changing the custom short type property name from ...
t3chb0t's user avatar
  • 44.3k
1 vote
3 answers
235 views

Visitor design pattern used for an asteroid game

Please review my code below. I am studying the Visitor Design Pattern and I think I have implemented it correctly. Please check. I have tried to split the method definitions and the prototypes as much ...
TradingDerivatives.eu's user avatar
4 votes
3 answers
1k views

Inline visitor implementation for C++11

I've been looking at getting back into C++11 after a few years and came across the idea of implementing the 'inline' visitor pattern. The idea is that you can specify your visitor class locally in the ...
the4thamigo_uk's user avatar
0 votes
1 answer
1k views

Golang visitor pattern for marshaling shapes as JSON, and XML

I was trying to implement visitor pattern in Golang, and came across an idea of using a generic func type instead if interface ...
Sergii Bishyr's user avatar
5 votes
2 answers
784 views

Visit each HTML element and apply inline CSS

I need to apply some css styles to an IMarkupElement. The generated HTML is only for emails so all styles are inline styles and the selectors are very simple, just ...
t3chb0t's user avatar
  • 44.3k
18 votes
2 answers
3k views

A KenKen puzzle/solver in Python

I've written a simple KenKen puzzle/solver in Python. I'd love some feedback on the design of the puzzle, as well as the architecture for the solver. To model the puzzle, I have the following classes:...
user138440's user avatar
1 vote
2 answers
259 views

Java sequential BFS

I am currently working on optimizing my code. In order to do that, I have to make sure that my sequential BFS works perfectly. Then, I should I apply threads or executor service to run it in parallel. ...
questioner's user avatar
4 votes
1 answer
2k views

C++ generic double-dispatcher/visitor

I'm trying to reduce the boilerplate code for the visitor/double dispatcher pattern. First I've created a way to enforce the dispatcher to declare the dispatch(T) function for every type supported and ...
Peter Lenkefi's user avatar
6 votes
1 answer
2k views

Modular Visitor Pattern

Motivation I created this because the Visitor pattern felt like the most appropriate, but I also wanted to satisfy the Open/Closed principle with respect to the logic when visiting specific node ...
John Neuhaus's user avatar
6 votes
2 answers
359 views

Visitor that changes the structure of the objects it visits

Brief summary: The vanilla GoF visitor is great for altering items within a tree of elements, but when the visitor visits an element it can only change the children of that element not the element ...
Jonny's user avatar
  • 161
7 votes
3 answers
738 views

Visitor Pattern/Leaky Bucket variant implementation to run an operation at a certain interval

My code is a variant on the Visitor Pattern and a "leaky bucket" variant. The goal is pretty straightforward: the "bucket" will collect a specified number of items (say, for example, 500) and then ...
EJoshuaS - Stand with Ukraine's user avatar
3 votes
0 answers
225 views

Using the visitor pattern to compose notifications

I'm solving the following problem using the Visitor design pattern in Swift: When a quote is requested or an appointment is booked we send out an email to the customer, and build an internal ...
Reza Shirazian's user avatar
3 votes
2 answers
712 views

Implementation of the visitor pattern

I tried implementing visitor patter and have questions about my usage of is and as keywords. Is there a big performance hit when ...
Liger86's user avatar
  • 109
5 votes
2 answers
23k views

Chess board representation in Java

I'm currently working on a small chess game written in Java (on GitHub). The board is modeled as a Board object with a 2D array of Piece objects : ...
fgero's user avatar
  • 61
13 votes
2 answers
7k views

Visitor pattern in C++

I have just implemented a quick test of the visitor design pattern in C++ and have a few questions regarding the code. main.cpp ...
Corporal Touchy's user avatar