<?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 on: Violations Of The “Tell, Don’t Ask” and “Don’t Repeat Yourself” Principles?</title>
	<atom:link href="http://lostechies.com/derickbailey/2010/05/27/violations-of-the-tell-don-t-ask-and-don-t-repeat-yourself-principles/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/derickbailey/2010/05/27/violations-of-the-tell-don-t-ask-and-don-t-repeat-yourself-principles/</link>
	<description>Better Than Yesterday</description>
	<lastBuildDate>Thu, 20 Jun 2013 04:02:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: Trystan Spangler</title>
		<link>http://lostechies.com/derickbailey/2010/05/27/violations-of-the-tell-don-t-ask-and-don-t-repeat-yourself-principles/#comment-3019</link>
		<dc:creator>Trystan Spangler</dc:creator>
		<pubDate>Fri, 01 Feb 2013 22:09:00 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2010/05/27/violations-of-the-tell-don-t-ask-and-don-t-repeat-yourself-principles.aspx#comment-3019</guid>
		<description>Another possible solution is &lt;a href=&#039;http://en.wikipedia.org/wiki/Continuation-passing_style&#039; rel=&quot;nofollow&quot;&gt;continuation passing style&lt;/a&gt;. Make your Handle method take an Action to use if it can handle the input and an Action for when it can&#039;t handle it. Sort of like success and failure callbacks. I can&#039;t say if it&#039;s better or not - but seems very Tell Don&#039;t Ask.</description>
		<content:encoded><![CDATA[<p>Another possible solution is <a href='http://en.wikipedia.org/wiki/Continuation-passing_style' rel="nofollow">continuation passing style</a>. Make your Handle method take an Action to use if it can handle the input and an Action for when it can&#8217;t handle it. Sort of like success and failure callbacks. I can&#8217;t say if it&#8217;s better or not &#8211; but seems very Tell Don&#8217;t Ask.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: deltreme</title>
		<link>http://lostechies.com/derickbailey/2010/05/27/violations-of-the-tell-don-t-ask-and-don-t-repeat-yourself-principles/#comment-3017</link>
		<dc:creator>deltreme</dc:creator>
		<pubDate>Fri, 01 Feb 2013 13:31:00 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2010/05/27/violations-of-the-tell-don-t-ask-and-don-t-repeat-yourself-principles.aspx#comment-3017</guid>
		<description>Anyone would use the same pattern for files: 

if (File.Exists(path)) 
  File.Open(path); 

As you should depend on the exception File.Open() would otherwise throw. I quite like the TryXxx alternatives from .NET:



int number;
if (int.TryParse(str, out number))
  ...</description>
		<content:encoded><![CDATA[<p>Anyone would use the same pattern for files: </p>
<p>if (File.Exists(path))<br />
  File.Open(path); </p>
<p>As you should depend on the exception File.Open() would otherwise throw. I quite like the TryXxx alternatives from .NET:</p>
<p>int number;<br />
if (int.TryParse(str, out number))<br />
  &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: crushcrush</title>
		<link>http://lostechies.com/derickbailey/2010/05/27/violations-of-the-tell-don-t-ask-and-don-t-repeat-yourself-principles/#comment-3016</link>
		<dc:creator>crushcrush</dc:creator>
		<pubDate>Fri, 01 Feb 2013 13:28:00 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2010/05/27/violations-of-the-tell-don-t-ask-and-don-t-repeat-yourself-principles.aspx#comment-3016</guid>
		<description>I think the idea is to encapsulate the &quot;CanHandle()&quot; logic inside of the GetMessageBody() function. If CanHandle() would be false, then GetMessageBody() would simply return an empty string.</description>
		<content:encoded><![CDATA[<p>I think the idea is to encapsulate the &#8220;CanHandle()&#8221; logic inside of the GetMessageBody() function. If CanHandle() would be false, then GetMessageBody() would simply return an empty string.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://lostechies.com/derickbailey/2010/05/27/violations-of-the-tell-don-t-ask-and-don-t-repeat-yourself-principles/#comment-963</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Tue, 08 Jun 2010 10:28:59 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2010/05/27/violations-of-the-tell-don-t-ask-and-don-t-repeat-yourself-principles.aspx#comment-963</guid>
		<description>Hi!
Why not do the following.. 
public class handler {
 IRequest _theRequest;
 public bool can_handle(IRequest someRequest) {
     /// figure out if it can handle then store someRequest locally.
    // if you cannot handle this... return false .. else...
      _theRequest = someRequest;
     return true;
}

      public void Handle(){ /*does what it needs to... */ }
      public IResult Handle() { /*does what it needs to but returns a status result... */ }

}

public class consumerClass {

  public void some_method() {
         
          foreach ( var item_to_test in some_collection_of_handlers ){
                    if (  item_to_test.can_handle(some_request) {
                            item_to_test.Handle();
                    }
          }

 
  }
}</description>
		<content:encoded><![CDATA[<p>Hi!<br />
Why not do the following..<br />
public class handler {<br />
 IRequest _theRequest;<br />
 public bool can_handle(IRequest someRequest) {<br />
     /// figure out if it can handle then store someRequest locally.<br />
    // if you cannot handle this&#8230; return false .. else&#8230;<br />
      _theRequest = someRequest;<br />
     return true;<br />
}</p>
<p>      public void Handle(){ /*does what it needs to&#8230; */ }<br />
      public IResult Handle() { /*does what it needs to but returns a status result&#8230; */ }</p>
<p>}</p>
<p>public class consumerClass {</p>
<p>  public void some_method() {</p>
<p>          foreach ( var item_to_test in some_collection_of_handlers ){<br />
                    if (  item_to_test.can_handle(some_request) {<br />
                            item_to_test.Handle();<br />
                    }<br />
          }</p>
<p>  }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Henning Anderssen</title>
		<link>http://lostechies.com/derickbailey/2010/05/27/violations-of-the-tell-don-t-ask-and-don-t-repeat-yourself-principles/#comment-962</link>
		<dc:creator>Henning Anderssen</dc:creator>
		<pubDate>Sun, 06 Jun 2010 22:26:54 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2010/05/27/violations-of-the-tell-don-t-ask-and-don-t-repeat-yourself-principles.aspx#comment-962</guid>
		<description>Why not use a event system, such as Udi Dahan&#039;s domain events.

http://www.udidahan.com/2009/06/14/domain-events-salvation/

It the GetThatFromIt passes, you send a passed event, else you send a failed event.
Then you can chain events that does one thing. Requires a bit more infrastructure in place, but I think events can solve a lot of problems :)</description>
		<content:encoded><![CDATA[<p>Why not use a event system, such as Udi Dahan&#8217;s domain events.</p>
<p><a href="http://www.udidahan.com/2009/06/14/domain-events-salvation/" rel="nofollow">http://www.udidahan.com/2009/06/14/domain-events-salvation/</a></p>
<p>It the GetThatFromIt passes, you send a passed event, else you send a failed event.<br />
Then you can chain events that does one thing. Requires a bit more infrastructure in place, but I think events can solve a lot of problems :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ian Cooper</title>
		<link>http://lostechies.com/derickbailey/2010/05/27/violations-of-the-tell-don-t-ask-and-don-t-repeat-yourself-principles/#comment-961</link>
		<dc:creator>Ian Cooper</dc:creator>
		<pubDate>Tue, 01 Jun 2010 12:22:07 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2010/05/27/violations-of-the-tell-don-t-ask-and-don-t-repeat-yourself-principles.aspx#comment-961</guid>
		<description>To remove an if statement polymorphism is your friend. Generally the model is something like this:

1: Ask factory to give you a strategy for your criteria
2: Exercise strategy

So in pseudo-code:

   1: public string GetMessageBody(string fileContents)

   2: {

   3:    4:   foreach(IFileFormatReader formatReader in _formatReaders)

   5:   {

   6:     var messageReader = new MessageReaderFactory(fileContents)
   7:       messageBody += messageReader .GetMessageBody();

 8:   return messageBody;

 9: }

Where a messageReader than cannot process the file contents simply returns an empty string. This latter part is really just a variation of the null object pattern.



</description>
		<content:encoded><![CDATA[<p>To remove an if statement polymorphism is your friend. Generally the model is something like this:</p>
<p>1: Ask factory to give you a strategy for your criteria<br />
2: Exercise strategy</p>
<p>So in pseudo-code:</p>
<p>   1: public string GetMessageBody(string fileContents)</p>
<p>   2: {</p>
<p>   3:    4:   foreach(IFileFormatReader formatReader in _formatReaders)</p>
<p>   5:   {</p>
<p>   6:     var messageReader = new MessageReaderFactory(fileContents)<br />
   7:       messageBody += messageReader .GetMessageBody();</p>
<p> 8:   return messageBody;</p>
<p> 9: }</p>
<p>Where a messageReader than cannot process the file contents simply returns an empty string. This latter part is really just a variation of the null object pattern.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew Chisholm</title>
		<link>http://lostechies.com/derickbailey/2010/05/27/violations-of-the-tell-don-t-ask-and-don-t-repeat-yourself-principles/#comment-960</link>
		<dc:creator>Andrew Chisholm</dc:creator>
		<pubDate>Sun, 30 May 2010 13:02:37 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2010/05/27/violations-of-the-tell-don-t-ask-and-don-t-repeat-yourself-principles.aspx#comment-960</guid>
		<description>Response&lt;T&gt; seems similar to the Maybe monad.  I&#039;ve used this in some C# projects which results in cleaner code and the ability to daisy chain methods together (fluent style).

See http://abdullin.com/journal/2009/10/6/zen-development-practices-c-maybe-monad.html or http://weblogs.asp.net/zowens/archive/2009/09/04/maybe-monad-my-c-version.aspx for examples</description>
		<content:encoded><![CDATA[<p>Response<t> seems similar to the Maybe monad.  I&#8217;ve used this in some C# projects which results in cleaner code and the ability to daisy chain methods together (fluent style).</p>
<p>See <a href="http://abdullin.com/journal/2009/10/6/zen-development-practices-c-maybe-monad.html" rel="nofollow">http://abdullin.com/journal/2009/10/6/zen-development-practices-c-maybe-monad.html</a> or <a href="http://weblogs.asp.net/zowens/archive/2009/09/04/maybe-monad-my-c-version.aspx" rel="nofollow">http://weblogs.asp.net/zowens/archive/2009/09/04/maybe-monad-my-c-version.aspx</a> for examples</t></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Ransley</title>
		<link>http://lostechies.com/derickbailey/2010/05/27/violations-of-the-tell-don-t-ask-and-don-t-repeat-yourself-principles/#comment-959</link>
		<dc:creator>Aaron Ransley</dc:creator>
		<pubDate>Sun, 30 May 2010 06:35:15 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2010/05/27/violations-of-the-tell-don-t-ask-and-don-t-repeat-yourself-principles.aspx#comment-959</guid>
		<description>@Bill Christie: I like your solution the most. Would lend the tightest syntax, so long as the FallbackAction wasn&#039;t too involved.</description>
		<content:encoded><![CDATA[<p>@Bill Christie: I like your solution the most. Would lend the tightest syntax, so long as the FallbackAction wasn&#8217;t too involved.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill Christie</title>
		<link>http://lostechies.com/derickbailey/2010/05/27/violations-of-the-tell-don-t-ask-and-don-t-repeat-yourself-principles/#comment-958</link>
		<dc:creator>Bill Christie</dc:creator>
		<pubDate>Fri, 28 May 2010 13:11:51 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2010/05/27/violations-of-the-tell-don-t-ask-and-don-t-repeat-yourself-principles.aspx#comment-958</guid>
		<description>Here is an alternative that is relatively simple to implement and can work well in certain situations.

public class TellDonTAskAlternative
{
    public void DoGoodThings()
    {
        var response something.GetThatFromIt(anotherThing, () =&gt; FallbackAction());
    }
}
</description>
		<content:encoded><![CDATA[<p>Here is an alternative that is relatively simple to implement and can work well in certain situations.</p>
<p>public class TellDonTAskAlternative<br />
{<br />
    public void DoGoodThings()<br />
    {<br />
        var response something.GetThatFromIt(anotherThing, () => FallbackAction());<br />
    }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Gregory</title>
		<link>http://lostechies.com/derickbailey/2010/05/27/violations-of-the-tell-don-t-ask-and-don-t-repeat-yourself-principles/#comment-957</link>
		<dc:creator>James Gregory</dc:creator>
		<pubDate>Fri, 28 May 2010 09:42:02 +0000</pubDate>
		<guid isPermaLink="false">/blogs/derickbailey/archive/2010/05/27/violations-of-the-tell-don-t-ask-and-don-t-repeat-yourself-principles.aspx#comment-957</guid>
		<description>For those people suggesting the Chain of Responsibility: &quot;Do not use Chain of Responsibility when each request is only handled by one handler, or, when the client object knows which service object should handle the request.&quot; -c2 wiki *

Derick&#039;s code implies that a request will only be handled by one handler,as the messageBody variable is overwritten rather than appended to.

Annoyingly though, the c2 wiki doesn&#039;t suggest alternatives for this situation.

* http://www.c2.com/cgi/wiki?ChainOfResponsibilityPattern

</description>
		<content:encoded><![CDATA[<p>For those people suggesting the Chain of Responsibility: &#8220;Do not use Chain of Responsibility when each request is only handled by one handler, or, when the client object knows which service object should handle the request.&#8221; -c2 wiki *</p>
<p>Derick&#8217;s code implies that a request will only be handled by one handler,as the messageBody variable is overwritten rather than appended to.</p>
<p>Annoyingly though, the c2 wiki doesn&#8217;t suggest alternatives for this situation.</p>
<p>* <a href="http://www.c2.com/cgi/wiki?ChainOfResponsibilityPattern" rel="nofollow">http://www.c2.com/cgi/wiki?ChainOfResponsibilityPattern</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
