Talk:Single-serving visitor pattern
![]() | This article has not yet been rated on Wikipedia's content assessment scale. It is of interest to the following WikiProjects: | |||||||||||||||||
|
The difference between this and Visitor is never clearly explained. The difference of what do they do is said (several times, indeed), but not how is that behaviour done. It's not until the implementation example in C++ that we can see that the method is static and the visitor is allocated and destroyed within it. It would be nice if somebody just wrote it down somewhere before the Pros/Cons section. --Euyyn
Vague and Trivial: needs deleting!!!
[edit]I'm sorry, but I have to say, this article is crap.
1) Not a pattern: The pattern described is not fundamentally a pattern but is rather a[n arbitrary] combination of two (the singleton pattern and the visitor pattern). The differences between this pattern and the original visitor pattern are either vague or arbitrary. This appears to be the documentation of a single individual's (pretty terrible) use of the visitor pattern. The fact that the visitor is "allocated only once" is either a direct consequence of using the singleton pattern (in one example) or the visitor's declaration as a local variable (in another). This single difference summarizes the whole article: store your [meant-for-one-thing] visitor in a singleton.
2) No real pros: In C++ (which seems to be the only language considered when writing this article), the "pros" of this pattern can easily be accomplished by declaring the visitor as a local variable (which gets auto-destroyed when it goes out of scope). It is actually shown this way in one example. This is extremely trivial and I doubt it justifies this article existing.
3) Crap code: The article hints at this, but using methods like "setParam1" is bad in the same way that global variables are bad. It's not thread safe (two threads simultaneously initializing [overwriting] the same properties at once. For single-threaded applications, it is not reentrant (while visiting one set of objects, a sub-process is started that wants to use the visitor for a different set, resulting in a modification of the [single] visitor before the first visit sequence completes). Even if these pitfalls were highlighted, the points above are by themselves good enough reasons to delete this article.
Single-serving visitor limited to non-gc languages?
[edit]Ummm ... I'm in a hurry and might be getting this wrong, but isn't this just a work-around so that a the visitor pattern can be used in non-garbage-collected languages? -- In other words, you would never want to use this pattern e.g. in Java, right? If so, please state that somewhere for clarification. Thanks a bunch. -- 193.99.145.162 10:30, 26 October 2006 (UTC)
Wrong (there's a but)... Can also be used with C#'s "using <object> { ... }" in a Java-like way. Also, the 'general' visitor pattern is implemented as easily in C++ as it is in Java. (It's even better in C++ specifically because you can rely on destructors being called exactly when they need to be. Look up RAII if interested.) But I agree with Tobei who seems to be too humble to suggest deletion.
Same here
[edit]Ya, I agree, this page looks more like the description of a particular implementation than a new pattern or pattern variation. As pattern should remain generic and not language oriented (they are design pattern). Tobei 15:10, 3 May 2007 (UTC)
Why?
[edit]So, if ApplyTo is static, why can't all of what ApplyTo does be contained within that static method or other static methods. Alan Evans 11:58, 24 October 2007 (UTC)