visitor-pattern

What is Single and Double Dispatch?

好久不见. 提交于 2019-12-01 03:58:18
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 class has two class hierarchy but it still considered as double dispatch. void floppyDisk::accept(equipmentVisitor* visitor) { visitor->visitFloppyDisk(this); } void processor::accept(equipmentVisitor* visitor) { visitor->visitProcessor(this); } void computer::accept

Visitor Design Pattern - return type

♀尐吖头ヾ 提交于 2019-11-30 21:08:12
I used the Visitor design pattern to solve one of the issues within our system. As a reference how to implement it I used DoFactory site and This YouTube video . In DoFactory example, the Visitor uses a method with return type of "void" and in YouTube video, author uses "double". Why I ask: After presenting the solution to company CTO, he accepted to call it Visitor, but he claims like if Visitor is not "void" as stated in GoF, than it like abuse the real Visitor pattern. Question: Is it required for Visitor pattern to return "void"? I mean in order to be "real Visitor pattern" as DoFactory

Visitor pattern implementation in java- How does this look?

情到浓时终转凉″ 提交于 2019-11-30 16:27:33
Alrite, I am gonna jump straight to the code: public interface Visitor { public void visitInventory(); public void visitMaxCount(); public void visitCountry(); public void visitSomethingElse(); public void complete(); //the idea of this visitor is that when a validator would visit it, it would validate data //when a persister visits it, it would persist data, etc, etc. // not sure if I making sense here... } public interface Visitable { public void accept(Visitor visitor); } here is a base implementation: public class StoreValidator implements Visitor { private List <ValidationError>

visitor pattern for boost::any

一个人想着一个人 提交于 2019-11-30 05:44:48
问题 I found this https://gist.github.com/2945472 but I need an implementation that does not depend on c++11. I tried my hand at converting it to use only boost, but I'm having some trouble. Here is what I came up with: #include <boost/any.hpp> #include <boost/function.hpp> #include <boost/bind.hpp> #include <boost/lambda/lambda.hpp> #include <boost/unordered_map.hpp> struct type_info_hash { std::size_t operator()(std::type_info const & t) const { return t.hash_code(); } }; struct equal_ref {

Visitor Design Pattern - return type

孤人 提交于 2019-11-30 05:07:11
问题 I used the Visitor design pattern to solve one of the issues within our system. As a reference how to implement it I used DoFactory site and This YouTube video. In DoFactory example, the Visitor uses a method with return type of "void" and in YouTube video, author uses "double". Why I ask: After presenting the solution to company CTO, he accepted to call it Visitor, but he claims like if Visitor is not "void" as stated in GoF, than it like abuse the real Visitor pattern. Question: Is it

Visitor pattern implementation in java- How does this look?

蓝咒 提交于 2019-11-29 23:32:08
问题 Alrite, I am gonna jump straight to the code: public interface Visitor { public void visitInventory(); public void visitMaxCount(); public void visitCountry(); public void visitSomethingElse(); public void complete(); //the idea of this visitor is that when a validator would visit it, it would validate data //when a persister visits it, it would persist data, etc, etc. // not sure if I making sense here... } public interface Visitable { public void accept(Visitor visitor); } here is a base

Generified implementation of Visitor pattern in Java

帅比萌擦擦* 提交于 2019-11-29 12:17:09
I've made some research trying to develop a type conversion framework which provides an ability to convert instances of a source class (e.g., Foo) to instances of result classes (e.g., Bar or Baz). The framework should provide an ability to use different conversion logic (i.e., different converters) for the same pair of a source and result. It also should be extendable, i.e. allow of adding new converters for new and existing pairs of a source and result. One more requirement is typesafety, i.e. any attempt to convert an instance of some source class to an instance of a result class without

Using the Visitor Pattern with template derived classes

风流意气都作罢 提交于 2019-11-29 02:45:35
I try to implement the Visitor pattern with templated derived classes I work with gcc 4.5 here is the VisitorTemplate.hpp, I specialized Derived in the class Visitor, but I'd like to be able to handle any type: edit : thanks to the suggestions of interjay, the code compiles and runs without errors now #ifndef VISITORTEMPLATE_HPP_ #define VISITORTEMPLATE_HPP_ #include <iostream> #include <string> using namespace std; template<class T> Derived; class Visitor { public: virtual void visit(Derived<string> *e) = 0; }; class Base { public: virtual void accept(class Visitor *v) = 0; }; template<class

How to write Visitor Pattern for a Abstract Syntax Tree in C#?

…衆ロ難τιáo~ 提交于 2019-11-28 23:30:20
I have to write a visitor pattern to navigate the AST. Can anyone tell me more how would I start writing it? As far as I understand, each Node in AST would have visit() method (?) that would somehow get called (from where?). That about concludes my understanding. To simplify everything, suppose I have nodes Root, Expression, Number, Op and the tree looks like this: Root | Op(+) / \ / \ Number(5) \ Op(*) / \ / \ / \ Number(2) Number(444) Pattern visitor is a design pattern that allows you to implement arbitrary operations (implemented as visitors) on the parse tree( eg. Type-checking ) without

Generified implementation of Visitor pattern in Java

蹲街弑〆低调 提交于 2019-11-28 05:36:26
问题 I've made some research trying to develop a type conversion framework which provides an ability to convert instances of a source class (e.g., Foo) to instances of result classes (e.g., Bar or Baz). The framework should provide an ability to use different conversion logic (i.e., different converters) for the same pair of a source and result. It also should be extendable, i.e. allow of adding new converters for new and existing pairs of a source and result. One more requirement is typesafety, i