visitor

what is the difference between using the visitor design pattern or using an interface ?

What is the difference between applying the visitor design pattern to your code , and code like the following : interface Dointerface { public void perform(Object o); } public class T { private Dointerface d; private String s; public String getS() { return s; } public T(String s) { t...

Unit testing Visitor pattern architecture

I've introduced visitors as one of core architecture ideas in one of my apps. I have several visitors that operate on a same stuff. Now, how should I test it? Some tests I'm thinking of are a bit larger then a unit test should be (integration test? whatever) but I still wanna do it. How would you test code like the C++ sample from wiki ...

Where am I losing the reference ?

I'm trying to use the Visitor Pattern and I have as follows: public class EnumerableActions<T> : IEnumerableActions<T> { private IEnumerable<T> itemsToActOn; public EnumerableActions ( IEnumerable<T> itemsToActOn ) { this.itemsToActOn = itemsToActOn; } public void VisitAllItemsUsing ( IVisitor<T> visitor ) { foreach (T t in items...

Extending both sides of a Visitor/Bridge pattern

Say I have a hierarchy of classes, let's use the classic Shape examples: abstract class Shape Circle : Shape Square : Shape I have a second hierarchy of renderer classes that handle the rendering of shapes in different ways: abstract class ShapeRenderer HtmlShapeRenderer : ShapeRenderer WindowsFormsShapeRenderer : ShapeRenderer Al...

Why use the Visitor Pattern?

Duplicate of: When Should I Use The Visitor Design Pattern Why would someone want to use the visitor pattern? I've read a couple of articles, but I'm not getting something. If I need a function to bill a custom, I could use Custom.Accept(BillVisitor) or something like Bill(Customer) The second is less complex, and the Bill functi...

Java: using a RuntimeException to escape from a Visitor

I am being powerfully tempted to use an unchecked exception as a short-circuit control-flow construct in a Java program. I hope somebody here can advise me on a better, cleaner way to handle this problem. The idea is that I want to cut short the recursive exploration of sub-trees by a visitor without having to check a "stop" flag in eve...

Getting Data From a Composite Control - Visitor Pattern?

I've got some rather complex forms, that need to be configured by web designers. I've been building some composite controls that appear to be doing the job. The top level control is simply a container, and the sections of the form are contained within. SubControls implement common interfaces, (i.e. NeptuneAddressControl and MarsAddres...

Is there a simple way to emulate Objective-C Categories in C#?

I have a weird design situation that I've never encountered before... If I were using Objective-C, I would solve it with categories, but I have to use C# 2.0. First, some background. I have two abstraction layers in this class library. The bottom layer implements a plug-in architecture for components that scan content (sorry, can't be m...

Using the visitor pattern with generics in C#

I want to know whether the below is an acceptable use of the visitor pattern. I feel a little uncomfortable returning from an Accept() or Visit() call - is this an appropriate usage of this pattern and if not, why not? Note: Apologies for the long code sample, seems necessary to get across what I'm doing as visitor always seems to be a ...

Itereting hierarchy of nodes - Visitor and Composite ?

Let's imagine I have a collection of nodes that I use for my Renderer class later on. Then I have a Visitor class that can visit node or whole collection. It's simple because my collection of nodes it's simply a wrapper to the std::list with few extra methods. The problem is I'd like to have a tree like structure for nodes(instead of si...

How to create a reliable and robust page view counter in a web application?

I want to count the visits on a web page, and this page represents an element of my model, just like the Stack Overflow question page views. How to do this in a reliable (one visit, one pageview, without repetitions) and robust (thinking on performance, not just a new table attribute 'visits_count') ...

Providing a feature only once to each unique visitor

I have written a message board as my first ASP.NET project. It seems to work well so far. However, one of the features I have is that each message has a spam rating. It is simply the number of times that viewers have marked the message as spam divided by the total number of times the message has been viewed. The idea is to allow users to...

Implementing a visitor counter

I am a newbie and developing a website using ASP .Net 2.0 with C# 2005. I would like to add a facility to count the no. of visitors to my website. I have collected the basic informations to add this feature using Global.asax. I have made modifications to Web.config by adding the line "" under system.web section. I am using a table to k...

Java field type for a value of a generically recursive self-type?

Given a class hierarchy where the base class defines a recursive self-type: abstract class A<T extends A<T>> { } How can I declare another class (which should not be generic in T, because such a T could vary over the lifetime of the object) with a field that can hold any subclass of A? The following does not work: public class B { ...

Visitor Design Pattern in OCaml

I am attempting to implement the Visitor Design Pattern using OCaml's OO constructs and type system and am running into problems upon instantiation of an Element. class virtual ['hrRep] employee = object method virtual receiveEvaluation : 'hrRep -> unit method virtual getName : string end;; class ['hrRep] accountant myName = object ...

Alternative to the visitor pattern?

I am looking for an alternative to the visitor pattern. Let me just focus on a couple of pertinent aspects of the pattern, while skipping over unimportant details. I'll use a Shape example (sorry!): You have a hierarchy of objects that implement the IShape interface You have a number of global operations that are to be performed on all...

Boost Graph Library and Visitors

I'm writing a library for manipulating bond graphs, and I'm using the Boost Graph Library to store the data for me. Unfortunately, I can't seem to figure out how to implement a proper visitor pattern using it, as you can't subclass out vertices - you must rely on 'properties' instead. The visitor framework provided in the library seems...

visitor pattern against conditionals?

I don't seem to find this in usage scenarios for the visitor pattern (or maybe I don't get it). It's also not hierarchical. Let's use an authentication example. A UserAuthenticator authenticates credentials given by a user. It returns a result object. The result object contains the result of the authentication: authentication succeeded,...

Building own C# compiler using ANTLR: Compilation Unit

Hi, // Create a scanner that reads from the input stream passed to us CSLexer lexer = new CSLexer(new ANTLRFileStream(f)); tokens.TokenSource = lexer; // Create a parser that reads from the scanner CSParser parser = new CSParser(tokens); // start parsing at the compilationUnit rule CSParser.compilation_unit_return x = parser.compilat...

Objective-C categories == visitor pattern?

Would you say that Objective-C categories are an implementation of the visitor design pattern? ...