Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [visitor-pattern]

The tag has no usage guidance.

2
votes
2answers
77 views

Combining composite, decorator and visitor patterns

I am currently working on a project where I need to manipulate a tree-like data structure, which I implemented with a composite pattern. I want to be able to do different actions on this data ...
2
votes
1answer
107 views

Traversing over two similar object structures using a pattern

Let's say I have an Object Structure like this that I import data into from a source: Reporting: Body: ReportingEntity: DocSpec Reports[]: ConstEntities[] DocSpec ...
4
votes
1answer
145 views

Circular dependency problem

"Single item in a set depends on the whole set. Set depends on that item." I'm creating a compiler (https://github.com/SuperJMN/Plotty). In the last stage, the Intermediate Code is converted to ...
0
votes
0answers
108 views

Design Pattern for a an ownership evaluator

I'm trying to refactor a module of a java application that checks ownership of different kinds of objects for specific accounts. E.g. a customer has multiple contracts that contain multiple domains, ...
-3
votes
1answer
74 views

Design help needed

I have a model call Drug class Drug{ String drugId; String name; String strength; } this interface takes a drugId and returns the Drug Model interface IProcessor{ getDrug(String drugId) } // easy ...
3
votes
1answer
435 views

Is it OK to use the Visitor pattern for queries?

On the net and in books you commonly see examples of the visitor pattern just using "commands" i.e. methods perform an action and have no return type. Is it OK to use this pattern for a query ...
1
vote
1answer
276 views

Visitor pattern and collecting visited data

I have a few operations to make over many similar elements. I would like to collect data from each element firstly and next bind all the data to an object (binding is expensive operation so I need to ...
5
votes
2answers
436 views

SAX-like parser: what is this pattern called?

I wrote a parser for a certain type of binary file with recursive structure. I made its API to be similar to SAX, that is: the parser accepts an object of a specific interface, this interface has ...
9
votes
5answers
3k views

Idiomatic pattern matching equivalent in Java

I'm building a simulator which parses some events from STDIN and "runs" them. My background is mostly functional programming these days, so it seemed natural to do something like this: data Event = ...
7
votes
1answer
743 views

Visitor Pattern, replacing objects

I have a program that translates a DSL to C++, which uses a Visitor pattern on the intermediate representation. I quite often need to replace the currently processed node with one of a different type ...
6
votes
3answers
998 views

Does the visitor pattern violate the Liskov Substitution Principle

When using the Visitor pattern, I have observed the following: The visitor has weak dependencies to concrete types (each visit method has the concrete element as a parameter or is a method that ...
5
votes
1answer
202 views

Determine equality of a DAG

Given a fairly traditional node class (below), what's the best way to implement equality on a given graph? If our node looks like this public abstract class Node{ private final Set<Node> ...
3
votes
3answers
235 views

Which pattern can I use for doing computations involving similar yet different object subtypes?

How do I design code that has two qualities: uses similar but different subtypes of an object uses similar but different types of computation on the above objects Example I am refactoring this ...
9
votes
4answers
893 views

Is Visitor Pattern valid in this scenario?

The goal of my task is to design a small system which can run scheduled recurring tasks. A recurring task is something like "send an email to administrator every hour from 8:00 am to 5:00 pm, Monday ...
5
votes
1answer
2k views

AST processing and usefulness of visitor pattern

I know the visitor pattern is typically used to traverse a hierarchy of heterogeneous objects (inheriting a same abstract object) and dissociate the processing of these objects from the data within ...
4
votes
2answers
2k views

Traversing an AST using Visitors

I'm writing a compiler for a C-like language, and I'm looking for an elegant way to traverse my abstract syntax tree. I'm trying to implement the Visitor pattern, although I'm not convinced that I'm ...
1
vote
2answers
391 views

Visitor only applicable when using the Composite pattern?

For a long time I've tried to get my head wrapped around the visitor pattern, and somehow this thing keeps being rather fuzzy to me. I'm currently under the impression it is only useful to apply ...
1
vote
2answers
201 views

Validating objects with each other - Design Pattern needed

I am running a zoo application. My zoo includes an abstract class of 'animal', and several deriving classes - 'zebra', 'elephant', 'orangutan', 'baboon' and so on. Of each class I have several ...
7
votes
2answers
9k views

Design for a tree using a visitor pattern, how to implement different kinds of traversal?

I've been asked a theoretical design question with an eye upon the GoF patterns.: "Given a design for a tree using a standard visitor pattern, how would your design look to allow a user to choose ...
4
votes
4answers
499 views

Visitor Pattern still useful in languages supporting class extensions?

Is the visitor pattern useful in languages supporting class extensions? Why bother implementing it, when you have open classes or can subclass. If you want new functionality for a class you could ...
22
votes
4answers
18k views

Implementing the Visitor Pattern for an Abstract Syntax Tree

I'm in the process of creating my own programming language, which I do for learning purposes. I already wrote the lexer and a recursive descent parser for a subset of my language (I currently support ...
10
votes
1answer
4k views

Using visitor pattern with large object hierarchy

Context I've been using with a hierarchy of objects (an expression tree) a "pseudo" visitor pattern (pseudo, as in it does not use double dispatch) : public interface MyInterface { void ...
1
vote
2answers
1k views

Use of the Visitor pattern and possible over engineering

I am developing a small application in .NET and am thinking of using XML to save the object model. My first thought was to separate the model and the generation of XML by using the Visitor pattern. ...