<?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: Null Object Pattern &#8211; Pattern or Antipattern</title>
	<atom:link href="http://www.unauthorised-access.com/2009/02/null-object-pattern/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.unauthorised-access.com/2009/02/null-object-pattern/</link>
	<description>Contains Nuts.</description>
	<lastBuildDate>Wed, 23 Nov 2011 09:38:18 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Dowell</title>
		<link>http://www.unauthorised-access.com/2009/02/null-object-pattern/comment-page-1/#comment-1348</link>
		<dc:creator>Dowell</dc:creator>
		<pubDate>Wed, 23 Nov 2011 09:38:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.unauthorised-access.com/?p=118#comment-1348</guid>
		<description>If you read the entire article you will see that the isNull-method is later removed in a refactoring step leaving only the simple call to getName.

However, I would argue that returning NullObjects are both a blessing and a curse (pattern/antipattern if you will). On one hand it is good to never have to worry about a method return breaking execution but on the other hand it may lead to unexpected side-effects as demonstrated with the infinite loop seen in this video:
http://www.youtube.com/watch?feature=player_detailpage&amp;v=hp1Y9bhail8</description>
		<content:encoded><![CDATA[<p>If you read the entire article you will see that the isNull-method is later removed in a refactoring step leaving only the simple call to getName.</p>
<p>However, I would argue that returning NullObjects are both a blessing and a curse (pattern/antipattern if you will). On one hand it is good to never have to worry about a method return breaking execution but on the other hand it may lead to unexpected side-effects as demonstrated with the infinite loop seen in this video:<br />
<a href="http://www.youtube.com/watch?feature=player_detailpage&#038;v=hp1Y9bhail8" rel="nofollow">http://www.youtube.com/watch?feature=player_detailpage&#038;v=hp1Y9bhail8</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Python</title>
		<link>http://www.unauthorised-access.com/2009/02/null-object-pattern/comment-page-1/#comment-1185</link>
		<dc:creator>Python</dc:creator>
		<pubDate>Mon, 09 Aug 2010 13:18:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.unauthorised-access.com/?p=118#comment-1185</guid>
		<description>Couldn&#039;t disagree with you more.

If the user cannot be found (e.g. because incorrect username was entered), this is indeed something exceptional (isn&#039;t supposed to happen with normal application usage), so I think throwing an exception is very appropriate in that case. 

Returning a guest user object will indeed not be appropriate in all cases, but it might be in some cases. 

You could consider null checking throughout the application code a form of safe programming. However, by doing so you make your code bloated and difficult to maintain (violation of the DRY principle). 

You could argue that null checking doesn&#039;t belong in the DAL (if you want to keep your DAL generic in the sense that it is not tailored to particular use-cases or application flows). However, this still is not a good reason to spread null checks thoughout your code. You could handle this elegantly in a seperate layer between your business layer and your DAL.

In short, I think having null checks EVERYWHERE in your code is bad. Having it in one place and one place only is good (whether this is in the DAL or some layer above that).</description>
		<content:encoded><![CDATA[<p>Couldn&#8217;t disagree with you more.</p>
<p>If the user cannot be found (e.g. because incorrect username was entered), this is indeed something exceptional (isn&#8217;t supposed to happen with normal application usage), so I think throwing an exception is very appropriate in that case. </p>
<p>Returning a guest user object will indeed not be appropriate in all cases, but it might be in some cases. </p>
<p>You could consider null checking throughout the application code a form of safe programming. However, by doing so you make your code bloated and difficult to maintain (violation of the DRY principle). </p>
<p>You could argue that null checking doesn&#8217;t belong in the DAL (if you want to keep your DAL generic in the sense that it is not tailored to particular use-cases or application flows). However, this still is not a good reason to spread null checks thoughout your code. You could handle this elegantly in a seperate layer between your business layer and your DAL.</p>
<p>In short, I think having null checks EVERYWHERE in your code is bad. Having it in one place and one place only is good (whether this is in the DAL or some layer above that).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Monty</title>
		<link>http://www.unauthorised-access.com/2009/02/null-object-pattern/comment-page-1/#comment-1183</link>
		<dc:creator>Monty</dc:creator>
		<pubDate>Sun, 08 Aug 2010 21:29:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.unauthorised-access.com/?p=118#comment-1183</guid>
		<description>Pyton - Exceptions should only be used in exceptional circumstances - not finding a user I don&#039;t think is classed as exceptional, as its expected - I would throw an exception if the server couldn&#039;t be found, for example.

ALL code should be checking for nulls - I wouldn&#039;t recommend returning a guest object either - If you call GetUser(&quot;Monty&quot;) - and Monty isnt found, then it shouldn&#039;t return a guest object (The method is called Get User - it should either get the user, or nothing).

You cant throw an exception if the user isn&#039;t found, you cant return a guest or empty object, so the only logical solution is to return null - the DAL&#039;s job is to return the user, or nothing at all. Its the business code&#039;s job to translate a null user object into &quot;No one found&quot;</description>
		<content:encoded><![CDATA[<p>Pyton &#8211; Exceptions should only be used in exceptional circumstances &#8211; not finding a user I don&#8217;t think is classed as exceptional, as its expected &#8211; I would throw an exception if the server couldn&#8217;t be found, for example.</p>
<p>ALL code should be checking for nulls &#8211; I wouldn&#8217;t recommend returning a guest object either &#8211; If you call GetUser(&#8220;Monty&#8221;) &#8211; and Monty isnt found, then it shouldn&#8217;t return a guest object (The method is called Get User &#8211; it should either get the user, or nothing).</p>
<p>You cant throw an exception if the user isn&#8217;t found, you cant return a guest or empty object, so the only logical solution is to return null &#8211; the DAL&#8217;s job is to return the user, or nothing at all. Its the business code&#8217;s job to translate a null user object into &#8220;No one found&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Python</title>
		<link>http://www.unauthorised-access.com/2009/02/null-object-pattern/comment-page-1/#comment-1181</link>
		<dc:creator>Python</dc:creator>
		<pubDate>Tue, 03 Aug 2010 13:31:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.unauthorised-access.com/?p=118#comment-1181</guid>
		<description>Implementing IsNull is indeed pointless as it doesn&#039;t solve anything. However, I disagree with the database example. Either you expect the database to return something and throw an exception if it doesn&#039;t (e.g. in your DAO code), or you do and handle this in an application-specific way (e.g. return the Guest user object in the above example). The point is that your business code shouldn&#039;t need to bother about checking for nulls.</description>
		<content:encoded><![CDATA[<p>Implementing IsNull is indeed pointless as it doesn&#8217;t solve anything. However, I disagree with the database example. Either you expect the database to return something and throw an exception if it doesn&#8217;t (e.g. in your DAO code), or you do and handle this in an application-specific way (e.g. return the Guest user object in the above example). The point is that your business code shouldn&#8217;t need to bother about checking for nulls.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

