Questions tagged [visitor-pattern]
The visitor-pattern tag has no summary.
                42 questions
            
            
            
                2
            
            votes
        
        
            
                5
            
            answers
        
        
            
                388
            
            views
        
        
            
            
        Does the Visitor Pattern necessitate traversing a structure of instances?
                    I have a class hierarchy of elements (more static) with different operations on them in another class hierarchy (more flexible). During execution there is exactly one element given, and based on it's ...
                
            
       
        
            
                1
            
            vote
        
        
            
                2
            
            answers
        
        
            
                634
            
            views
        
        
            
            
        Message Dispatching: If, Visitor, or something else
                    I often write code to implement the dispatching and handling of "messages."  My requirements are usually:
I should be able to add new types of messages AND/OR new types of handlers without ...
                
            
       
        
            
                3
            
            votes
        
        
            
                1
            
            answer
        
        
            
                803
            
            views
        
        
            
            
            
        How to implement the visitor pattern without inheritance
                    I write embedded firmware using C++.  A common job for firmware is to "handle" different types of "messages" (e.g., in a communication protocol).  The "C" way of doing ...
                
            
       
        
            
                0
            
            votes
        
        
            
                3
            
            answers
        
        
            
                1k
            
            views
        
        
            
            
        Use of Visitor pattern rather than enums
                    Lets say that a enum exists:
public enum SomeEnum
{
    FirstValue,
    SecondValue
}
It's use is spread through the code and all sort of wonderful logic hangs off it.
If we now add another entry (...
                
            
       
        
            
                -1
            
            votes
        
        
            
                1
            
            answer
        
        
            
                346
            
            views
        
        
            
            
        Avoid use of the visitor pattern in this very common scenario
                    Let's assume we need to send a message, and to do so we would like our client to be concerned only with constructing the message (DTO) and using a facade service to send it.
We already know that we ...
                
            
       
        
            
                1
            
            vote
        
        
            
                1
            
            answer
        
        
            
                572
            
            views
        
        
            
            
            
        Does every Visited class have to be aware of the Visitor interface?
                    I'm taking another look at the pros and cons of the Visitor design pattern for a talk.
There's obviously the issue that the Visitor has to be aware of every class it has specific handling for, but ...
                
            
       
        
            
                1
            
            vote
        
        
            
                1
            
            answer
        
        
            
                291
            
            views
        
        
            
            
        How to implement visitor if not all functions are supported for each Element?
                    I have two Visitor classes in my code Visitor1 and Visitor2 that execute functions on the classes ElementA and ElementB (both implement the interface Visitable that defines accept(Visitor)).
I do not ...
                
            
       
        
            
                1
            
            vote
        
        
            
                2
            
            answers
        
        
            
                949
            
            views
        
        
            
            
        Appropriate use for the visitor design pattern
                    Assume I have a factory which takes in a series of bytes and outputs a pointer to a newly-created abstract message.
Now, I would like to define some extensible, manageable, and clean way to "...
                
            
       
        
            
                1
            
            vote
        
        
            
                1
            
            answer
        
        
            
                771
            
            views
        
        
            
        Is using lambdas and overload resolution a recommended way to write a visitor for a variant?
                    If I have a discriminated union and want to write a function piecewise, the following code works just fine, but is taking advantage of some fairly tricky (at least to me) stuff involving overload ...
                
            
       
        
            
                2
            
            votes
        
        
            
                2
            
            answers
        
        
            
                2k
            
            views
        
        
            
            
        Alternative to the Visitor Design Pattern
                    I have been trying to come up with a method to "serialize" various objects into various different formats.  For example:
class Shape {
public:
    virtual std::string_view name() const = 0;
 ...
                
            
       
        
            
                3
            
            votes
        
        
            
                2
            
            answers
        
        
            
                856
            
            views
        
        
            
            
        How to use visitor pattern when objects change frequently
                    It is said that visitor pattern is applicable to problems where objects rarely change but we add actions on those objects more frequently.
What if the objects are changing too though? For example we ...
                
            
       
        
            
                1
            
            vote
        
        
            
                1
            
            answer
        
        
            
                473
            
            views
        
        
            
            
        Rock Paper Scissors with Visitor Pattern
                    I've been going over the Visitor Pattern to try to understand it. Is this a correct implementation of the Visitor Pattern for RPS??
Here's the implementation code:
public enum ResultEnum {
    WIN,
 ...
                
            
       
        
            
                2
            
            votes
        
        
            
                1
            
            answer
        
        
            
                194
            
            views
        
        
            
            
            
        Loose coupling vs transparency in visitor pattern that visits composite
                    I have a composite object (I will call it A) that has fixed number of sons (I will call them A1 and A2)
All of them have an Accept(Visitor) method.
I have a GUI, A is the main window that consists of ...
                
            
       
        
            
                1
            
            vote
        
        
            
                0
            
            answers
        
        
            
                191
            
            views
        
        
            
        Visitor pattern with internal iterators
                    I'm trying to understand the following description of implementing the visitor pattern with an internal iterator. It is from the GoF's Design Pattern Elements of Reusable Object-Oriented Software book ...
                
            
       
        
            
                -2
            
            votes
        
        
            
                1
            
            answer
        
        
            
                60
            
            views
        
        
            
            
        Inheritance and domain-specific logic loses its independency?
                    Im sorry in forward, Im sure I wont be able to express myself well.
Its a game system:
abstract class GameType
{
    private $score;
    public __constructor($score)
    {
        $this->score = $...
                
            
       
         
         
        