visitor-pattern

When do you decide to use a visitors for your objects?

I always thought an object needs the data and the messages to act on it. When would you want a method that is extrinsic to the object? What rule of thumb do you follow to have a visitor? This is supposing that you have full control of the object graph. ...

Visitor and templated virtual methods

In a typical implementation of the Visitor pattern, the class must account for all variations (descendants) of the base class. There are many instances where the same method content in the visitor is applied to the different methods. A templated virtual method would be ideal in this case, but for now, this is not allowed. So, can te...

Need help make these classes use Visitor Pattern and generics

Hi. I need help to generify and implement the visitor pattern. We are using tons of instanceof and it is a pain. I am sure it can be modified, but I am not sure how to do it. Basically we have an interface ProcessData public interface ProcessData { public setDelegate(Object delegate); public Object getDelegate(); //I am sure the...

What is Single and Double Dispatch ?

Hello to all, i have wrote the visitor pattern as follow but i don't understand what is single and double dispatch. AFAIK, single dispatch is invoke a method based on caller type where double dispatch is invoke a method based on caller type and argument type. I guess double dispatch is happen in single class hierarchy but why visitor ...

Is the Visitor pattern the best way to refactor domain enums to classes?

If we want to refactor an enum (contained in the domain layer) to a polymorphic class, using "simple" abstract methods could be a bad idea, if all the switch and if statements we want to refactor are inside the other layers (like the business or the presentation layer), because we could end up to reference these layers inside the domain ...

Implementing visitor pattern on aggregate objects

I'm struggling with applying the visitor pattern on some objects that have scalar members and at the same time aggregate members (collections). These are the objects that I have: Artist - id - name - .. more scalar values .. - worksOfArt <-- this is a collection as WorkOfArt instances WorkOfArt - id - name - .. more scalar val...

Is the Visitor Pattern the fastest way to differentiate parameter types in C++?

Is the Visitor Pattern the fastest way to accomplish method parameter type identification (effectively single dispatch on a parameter, not a member's class) in C++? I might know the exact method(s) I want to invoke on elements of not-yet-know subtype, so invariably making an additional virtual method call like V::visit(A *) in A::accept...

A good reason to use the Visitor design pattern?

Before you tell me that there is already a similar question, yes, i know, I've read it. But the question there focuses on when, I'm interested in why. I get how the things work. The classic animal,dog,cat example always works like a charm. The thing is this code int main() { Cat c; Sound theSound; c.letsDo(&theSound); } ...

Event handling in component based game engine design

I imagine this question or variations of it get passed around a lot, so if what I'm saying is a duplicate, and the answers lie elsewhere, please inform me. I have been researching game engine designs and have come across the component-based entity model. It sounds promising, but I'm still working out its implementation. I'm considerin...

How to modify a pre-defined package methods outside of the package?

Let's say I have a package called 'animal' including Animal parent class, Cat extends from Animal, Dog extends from Animal, also. Animal, however, is designed like this: class Animal { int amount; Animal next; // Then a constructor initializes these. drinkWater(int n) { ... } } Cat & Dog classes follow this structure: class Ca...

Design pattern "Container Visitor" without virtual methods?

Hi everybody, I am developing the design of an application and I thought I might apply some sort of the Visitor design pattern, but it turned out that it's not exactly what I am looking for. Maybe someone can point me to the variant I require in this case? Much of my code has a template argument "ContainerType" like template <class Co...

Blitting in the right order - a visitor problem

I'm designing a simple GUI. I have Widgets, which have children and one parent. Each Widget is a Composite object, with a vector of WidgetComposite objects. One of those WidgetComposites is a PaintingBehaviour, but the Widget doesn't know it as such. To display my window, I use a Visitor, called the ScreenVisitor. When the Visitor is c...