<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments for .Org</title>
	<atom:link href="http://philiphanson.org/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://philiphanson.org</link>
	<description>Code for the social web, data management, and other interesting things.</description>
	<lastBuildDate>Thu, 16 Jun 2011 11:01:32 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>Comment on Generic Visitor Pattern in C# by Philip Hanson</title>
		<link>http://philiphanson.org/2010/generic-visitor-pattern-csharp/#comment-48</link>
		<dc:creator>Philip Hanson</dc:creator>
		<pubDate>Thu, 16 Jun 2011 11:01:32 +0000</pubDate>
		<guid isPermaLink="false">http://philiphanson.org/?p=17#comment-48</guid>
		<description>Daniel,

No problem. I did not catch this at first, as I was writing it as an exercise and did not have occasion to rewrite any visitor classes to use this type of pattern.

Note that it is still useful to point out the generic parameterized visitor, though obviously that is not a new development. The same effect can be had by storing state in the visitor, but that does not let you program in as functional of a style.

I would simply revise the post, but I feel like that would be dishonest. However, I will put a note at the bottom.</description>
		<content:encoded><![CDATA[<p>Daniel,</p>
<p>No problem. I did not catch this at first, as I was writing it as an exercise and did not have occasion to rewrite any visitor classes to use this type of pattern.</p>
<p>Note that it is still useful to point out the generic parameterized visitor, though obviously that is not a new development. The same effect can be had by storing state in the visitor, but that does not let you program in as functional of a style.</p>
<p>I would simply revise the post, but I feel like that would be dishonest. However, I will put a note at the bottom.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Generic Visitor Pattern in C# by Daniel Gröndal</title>
		<link>http://philiphanson.org/2010/generic-visitor-pattern-csharp/#comment-47</link>
		<dc:creator>Daniel Gröndal</dc:creator>
		<pubDate>Wed, 15 Jun 2011 09:55:35 +0000</pubDate>
		<guid isPermaLink="false">http://philiphanson.org/?p=17#comment-47</guid>
		<description>Hi!

Sorry if I broke something :-). I just could not get it.

What you are doing in your last post is nothing but a &quot;type switch&quot; which is what I would use the Visitor pattern to avoid.

//daniel</description>
		<content:encoded><![CDATA[<p>Hi!</p>
<p>Sorry if I broke something <img src='http://philiphanson.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> . I just could not get it.</p>
<p>What you are doing in your last post is nothing but a &#8220;type switch&#8221; which is what I would use the Visitor pattern to avoid.</p>
<p>//daniel</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Generic Visitor Pattern in C# by Philip Hanson</title>
		<link>http://philiphanson.org/2010/generic-visitor-pattern-csharp/#comment-46</link>
		<dc:creator>Philip Hanson</dc:creator>
		<pubDate>Thu, 02 Jun 2011 02:07:41 +0000</pubDate>
		<guid isPermaLink="false">http://philiphanson.org/?p=17#comment-46</guid>
		<description>Daniel,

You are correct that a typical implementation of the Visitor pattern using this generic setup does not work without some finessing. In fact, if you try it as-is you will get a StackOverflowException. Unfortunately this way of writing a visitor requires extra checks in the visitor class itself. For instance, with model classes Building, Room, and Item:

&lt;code&gt;
public string Visit(IVisitable visitable, string data)
{
    if (visitable == null)
        return data;

    Building b = visitable as Building;
    if (b != null)
        return this.Visit(b, data);

    Room r = visitable as Room;
    if (r != null)
        return this.Visit(r, data);

    Item i = visitable as Item;
    if (i != null)
        return this.Visit(i, data);

    return null;
}
&lt;/code&gt;

Note that the visitor already had knowledge of the specific classes involved, as it provides overloads for them. However, this is somewhat ugly. Furthermore, it means that we lose some of the static type checking afforded by the compiler -- i.e., if I add another type, I have to remember to check it in the top-level visit method, and the compiler won&#039;t complain if I don&#039;t.

Now that I&#039;ve had the chance to evaluate this approach again, I think that it is better not to attempt to use fancy extension methods for this purpose. The first part of the post is still valid, I think.</description>
		<content:encoded><![CDATA[<p>Daniel,</p>
<p>You are correct that a typical implementation of the Visitor pattern using this generic setup does not work without some finessing. In fact, if you try it as-is you will get a StackOverflowException. Unfortunately this way of writing a visitor requires extra checks in the visitor class itself. For instance, with model classes Building, Room, and Item:</p>
<p><code><br />
public string Visit(IVisitable visitable, string data)<br />
{<br />
    if (visitable == null)<br />
        return data;</p>
<p>    Building b = visitable as Building;<br />
    if (b != null)<br />
        return this.Visit(b, data);</p>
<p>    Room r = visitable as Room;<br />
    if (r != null)<br />
        return this.Visit(r, data);</p>
<p>    Item i = visitable as Item;<br />
    if (i != null)<br />
        return this.Visit(i, data);</p>
<p>    return null;<br />
}<br />
</code></p>
<p>Note that the visitor already had knowledge of the specific classes involved, as it provides overloads for them. However, this is somewhat ugly. Furthermore, it means that we lose some of the static type checking afforded by the compiler &#8212; i.e., if I add another type, I have to remember to check it in the top-level visit method, and the compiler won&#8217;t complain if I don&#8217;t.</p>
<p>Now that I&#8217;ve had the chance to evaluate this approach again, I think that it is better not to attempt to use fancy extension methods for this purpose. The first part of the post is still valid, I think.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Generic Visitor Pattern in C# by Philip Hanson</title>
		<link>http://philiphanson.org/2010/generic-visitor-pattern-csharp/#comment-45</link>
		<dc:creator>Philip Hanson</dc:creator>
		<pubDate>Wed, 01 Jun 2011 00:44:27 +0000</pubDate>
		<guid isPermaLink="false">http://philiphanson.org/?p=17#comment-45</guid>
		<description>Hi Daniel!

You raise a fair concern. I think it may be that I am not explaining the generics properly, but it very well could be that I am not understanding your comment properly and have made a mistake! I will put together an example and post it in the next day or two, as time allows.

Philip</description>
		<content:encoded><![CDATA[<p>Hi Daniel!</p>
<p>You raise a fair concern. I think it may be that I am not explaining the generics properly, but it very well could be that I am not understanding your comment properly and have made a mistake! I will put together an example and post it in the next day or two, as time allows.</p>
<p>Philip</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Generic Visitor Pattern in C# by Daniel Gröndal</title>
		<link>http://philiphanson.org/2010/generic-visitor-pattern-csharp/#comment-44</link>
		<dc:creator>Daniel Gröndal</dc:creator>
		<pubDate>Tue, 31 May 2011 11:04:15 +0000</pubDate>
		<guid isPermaLink="false">http://philiphanson.org/?p=17#comment-44</guid>
		<description>Hi!

I fail to see how this actually solves the same problem as a Visitor pattern do. Could you provide a sample on how to use this? Extension methods are static and cannot therefore be virtual. So the compiler needs an exact type on compilation to resolve such a call. Using a Visitor pattern is useful when you have base class pointers pointing to a derived type that is not known at compile time.

//daniel</description>
		<content:encoded><![CDATA[<p>Hi!</p>
<p>I fail to see how this actually solves the same problem as a Visitor pattern do. Could you provide a sample on how to use this? Extension methods are static and cannot therefore be virtual. So the compiler needs an exact type on compilation to resolve such a call. Using a Visitor pattern is useful when you have base class pointers pointing to a derived type that is not known at compile time.</p>
<p>//daniel</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Three-Legged Products by momochii</title>
		<link>http://philiphanson.org/2011/three-legged-products/#comment-43</link>
		<dc:creator>momochii</dc:creator>
		<pubDate>Mon, 23 May 2011 08:06:14 +0000</pubDate>
		<guid isPermaLink="false">http://philiphanson.org/?p=49#comment-43</guid>
		<description>I’ve recently started a blog, the information you provide on this site has helped me tremendously. Thank you for all of your time &amp; work.</description>
		<content:encoded><![CDATA[<p>I’ve recently started a blog, the information you provide on this site has helped me tremendously. Thank you for all of your time &amp; work.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

