<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Being descriptive in code when building objects</title><link>http://weblogs.asp.net/bsimser/archive/2007/07/26/being-descriptive-in-code-when-building-objects.aspx</link><description>As we're working through the course, I've been struggling with some constructors of objects we create. For example, in the first couple of days the team was writing unit tests around creating video game objects. This would be done by specifying a whack</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Link Listing - July 28, 2007</title><link>http://weblogs.asp.net/bsimser/archive/2007/07/26/being-descriptive-in-code-when-building-objects.aspx#3315295</link><pubDate>Sun, 29 Jul 2007 03:52:29 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:3315295</guid><dc:creator>Christopher Steen</dc:creator><author>Christopher Steen</author><description>&lt;p&gt;Link Listing - July 28, 2007&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=3315295" width="1" height="1"&gt;</description></item><item><title>re: Being descriptive in code when building objects</title><link>http://weblogs.asp.net/bsimser/archive/2007/07/26/being-descriptive-in-code-when-building-objects.aspx#3296762</link><pubDate>Fri, 27 Jul 2007 19:45:33 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:3296762</guid><dc:creator>Bil Simser</dc:creator><author>Bil Simser</author><description>&lt;p&gt;@William: Yes. Can you tell me what's more readable:&lt;/p&gt;
&lt;p&gt;Person person = new Person(10, 100, &amp;quot;Abel&amp;quot;);&lt;/p&gt;
&lt;p&gt;vs.&lt;/p&gt;
&lt;p&gt;Person person = PersonBuilder.&lt;/p&gt;
&lt;p&gt; &amp;nbsp;StartRecording().&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;CreateWithFirstName(&amp;quot;Abel&amp;quot;).&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;IsOfTheAgeOf(10).&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;WithNumberOfComputersInHouse(100).&lt;/p&gt;
&lt;p&gt; &amp;nbsp;Finish();&lt;/p&gt;
&lt;p&gt;Okay, grant you could write:&lt;/p&gt;
&lt;p&gt;Person person = new Person();&lt;/p&gt;
&lt;p&gt;person.FirstName = &amp;quot;Abel&amp;quot;;&lt;/p&gt;
&lt;p&gt;person.Age = 10;&lt;/p&gt;
&lt;p&gt;person.ComputersInHouse = 100;&lt;/p&gt;
&lt;p&gt;However I have to create properties for all of that and if I were to change those properties (maybe to be more descriptive, maybe to remove them) I would have to update all places where I have this code. With the Builder I can a) direct my developers to the Builder if they need to update how Person is created and b) my consuming code is more readable than parameterized constructors. I mean really, did you know what 10 and 100 were in the constructor before you saw the rest of the code? The less code I have to crack open, read, interpret, and understand the better.&lt;/p&gt;
&lt;p&gt;To each their own though. &lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=3296762" width="1" height="1"&gt;</description></item><item><title>re: Being descriptive in code when building objects</title><link>http://weblogs.asp.net/bsimser/archive/2007/07/26/being-descriptive-in-code-when-building-objects.aspx#3296680</link><pubDate>Fri, 27 Jul 2007 19:11:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:3296680</guid><dc:creator>William</dc:creator><author>William</author><description>&lt;p&gt;I&amp;#39;m sorry. &amp;nbsp;You have got to be joking. &amp;nbsp;You think the Builder class makes instantiating your object MORE readable??&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=3296680" width="1" height="1"&gt;</description></item><item><title>re: Being descriptive in code when building objects</title><link>http://weblogs.asp.net/bsimser/archive/2007/07/26/being-descriptive-in-code-when-building-objects.aspx#3295075</link><pubDate>Fri, 27 Jul 2007 14:08:35 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:3295075</guid><dc:creator>Nate Kohari</dc:creator><author>Nate Kohari</author><description>&lt;p&gt;I agree that in this case, the fluent interface isn&amp;#39;t necessary. But like Bil said, it&amp;#39;s not meant for production, and as an example of fluent interface design, it works well.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=3295075" width="1" height="1"&gt;</description></item><item><title>re: Being descriptive in code when building objects</title><link>http://weblogs.asp.net/bsimser/archive/2007/07/26/being-descriptive-in-code-when-building-objects.aspx#3294659</link><pubDate>Fri, 27 Jul 2007 12:35:31 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:3294659</guid><dc:creator>Jason Dossett</dc:creator><author>Jason Dossett</author><description>&lt;p&gt;Hey Bil, some people get syntactic sugar, some don&amp;#39;t. I&amp;#39;m picturing auto-generated builder classes generated from a class based on custom attributes on public or private properties that let the generator know which helper methods to create and what to name them. I think there is potential there.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=3294659" width="1" height="1"&gt;</description></item><item><title>re: Being descriptive in code when building objects</title><link>http://weblogs.asp.net/bsimser/archive/2007/07/26/being-descriptive-in-code-when-building-objects.aspx#3289370</link><pubDate>Thu, 26 Jul 2007 23:38:11 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:3289370</guid><dc:creator>Bil Simser</dc:creator><author>Bil Simser</author><description>&lt;p&gt;@CodeMan/@Joe: Yes, there are properties and they would read well, but what if I want to pass in one value and set two? In the builder, I can take in a value, set a property and even combine values into readable methods.&lt;/p&gt;
&lt;p&gt;@Aaron: Agreed, and really this is just sample code for an idea, it's not meant to be production code.&lt;/p&gt;
&lt;p&gt;Guys, the point here (which was obviously missed probably due to my own inability to be expressive) is that you favor readability over creating parameters to a constructor or having to name properties (or even create them). Why must I expose the inner workings of an object to the outside world or maybe have to create properties that sound correct when I don't need to. It's the same as creating a named interface that simply wraps a generic. I would rather use the domain specific language of IVideoGameRental in my domain, than the programmer-speak of IInterface&amp;lt;IVideoGame, IRental&amp;gt;. The less code I have to crack open to actual read in order to gain intent and understanding, the better.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=3289370" width="1" height="1"&gt;</description></item><item><title>re: Being descriptive in code when building objects</title><link>http://weblogs.asp.net/bsimser/archive/2007/07/26/being-descriptive-in-code-when-building-objects.aspx#3289065</link><pubDate>Thu, 26 Jul 2007 23:09:08 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:3289065</guid><dc:creator>Aaron Jensen</dc:creator><author>Aaron Jensen</author><description>&lt;p&gt;That&amp;#39;s a ton of work to put in (unless you generate this...) for what I consider minimal gain... you can always just wait a bit for C# 3.0&amp;#39;s anonymous constructors.&lt;/p&gt;
&lt;p&gt;Oh, and to clean things up a bit you may consider ditching StartRecording/Finish and adding an implicit operator VideoGame to VideoGameBuilder.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=3289065" width="1" height="1"&gt;</description></item><item><title>re: Being descriptive in code when building objects</title><link>http://weblogs.asp.net/bsimser/archive/2007/07/26/being-descriptive-in-code-when-building-objects.aspx#3288666</link><pubDate>Thu, 26 Jul 2007 22:41:19 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:3288666</guid><dc:creator>Joe Chung</dc:creator><author>Joe Chung</author><description>&lt;p&gt;Umm, yeah, there are also these things called &amp;quot;properties.&amp;quot;&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=3288666" width="1" height="1"&gt;</description></item><item><title>re: Being descriptive in code when building objects</title><link>http://weblogs.asp.net/bsimser/archive/2007/07/26/being-descriptive-in-code-when-building-objects.aspx#3288199</link><pubDate>Thu, 26 Jul 2007 21:45:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:3288199</guid><dc:creator>CodeMan</dc:creator><author>CodeMan</author><description>&lt;p&gt;Your class has a default constructor why not just set the individual properties your self. &amp;nbsp;The game builder appears to provide no value, other the the ability to chain the calls to gather what is the point.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=3288199" width="1" height="1"&gt;</description></item></channel></rss>