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
1
vote
0answers
42 views

AST Visitor Pattern in Java

I am trying to make a simple expression evaluator in Java using Jacc (a parser generator). I am done with the AST creation and now need to create an evaluator. For this I made a simple test to try to ...
5
votes
0answers
147 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 ...
1
vote
3answers
144 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 ...
3
votes
2answers
525 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 ...
0
votes
1answer
557 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 ...
4
votes
2answers
589 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 ...
16
votes
2answers
1k 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:...
1
vote
2answers
153 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. ...
3
votes
1answer
856 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 ...
5
votes
1answer
1k 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 ...
6
votes
2answers
306 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 ...
7
votes
3answers
499 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 ...
3
votes
0answers
171 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 ...
2
votes
2answers
586 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 ...
5
votes
2answers
20k 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 : ...
13
votes
2answers
6k 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 ...