<?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: C# Object Initializer: More thoughts</title>
	<atom:link href="http://www.markhneedham.com/blog/2010/01/10/c-object-initializer-more-thoughts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.markhneedham.com/blog/2010/01/10/c-object-initializer-more-thoughts/</link>
	<description>Thoughts on Software Development</description>
	<lastBuildDate>Sat, 11 Feb 2012 23:17:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Owen Pellegrin</title>
		<link>http://www.markhneedham.com/blog/2010/01/10/c-object-initializer-more-thoughts/comment-page-1/#comment-30141</link>
		<dc:creator>Owen Pellegrin</dc:creator>
		<pubDate>Tue, 12 Jan 2010 17:56:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=2016#comment-30141</guid>
		<description>I&#039;m not really sure why constructors weren&#039;t used in the first place, regardles of whether tiny types are used.  Fluent interfaces are *nice*, but to some extent it feels like they came about because someone felt like constructors were boring and decided to create some way to not use constructors.

Maybe the article is just a poor example.  In my mind, if my class has members that *cannot* be null when it is used, then I want to enforce this in as clear a manner as possible.  With a fluent interface or object initializers, the only enforcement comes at runtime when you chastize the user for forgetting to add a call to Foo() or to set the Foo property.  This can happen very far away from where you created the object in many cases, which makes it hard to track the cause down.  With constructors, you&#039;re either going to get the error at compile time or object creation; in either case it&#039;s really clear where you went wrong and probably clear what you did.

I like object initializers and fluent interfaces for setting *optional* properties of an object.  Fluent interfaces are also nice when you&#039;re using something like Decorator to add behavior to a base type.  But if a class *requires* me to pass it some parameter, that should be a constructor parameter with validation so that it hurts immediately when I shoot myself in the foot.</description>
		<content:encoded><![CDATA[<p>I&#8217;m not really sure why constructors weren&#8217;t used in the first place, regardles of whether tiny types are used.  Fluent interfaces are *nice*, but to some extent it feels like they came about because someone felt like constructors were boring and decided to create some way to not use constructors.</p>
<p>Maybe the article is just a poor example.  In my mind, if my class has members that *cannot* be null when it is used, then I want to enforce this in as clear a manner as possible.  With a fluent interface or object initializers, the only enforcement comes at runtime when you chastize the user for forgetting to add a call to Foo() or to set the Foo property.  This can happen very far away from where you created the object in many cases, which makes it hard to track the cause down.  With constructors, you&#8217;re either going to get the error at compile time or object creation; in either case it&#8217;s really clear where you went wrong and probably clear what you did.</p>
<p>I like object initializers and fluent interfaces for setting *optional* properties of an object.  Fluent interfaces are also nice when you&#8217;re using something like Decorator to add behavior to a base type.  But if a class *requires* me to pass it some parameter, that should be a constructor parameter with validation so that it hurts immediately when I shoot myself in the foot.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

