<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/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>Strongly Typed Primitives</title><link>http://blogs.msdn.com/simonince/archive/2008/08/15/strongly-typed-primitives.aspx</link><description>No, I’m not talking about NEANDERTHALS (there’s a joke in there somewhere), but rather a technique that a colleague of mine, Josh Twist , has recently blogged about – “ Avoiding Primitive Obsession to tip developers into the pit of success ”. I’d always</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>discount furniture &amp;raquo; Strongly Typed Primitives</title><link>http://blogs.msdn.com/simonince/archive/2008/08/15/strongly-typed-primitives.aspx#8869629</link><pubDate>Fri, 15 Aug 2008 16:38:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8869629</guid><dc:creator>discount furniture &amp;raquo; Strongly Typed Primitives</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://informationsfunnywallpaper.cn/?p=740"&gt;http://informationsfunnywallpaper.cn/?p=740&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Strongly Typed Primitives</title><link>http://blogs.msdn.com/simonince/archive/2008/08/15/strongly-typed-primitives.aspx#8869637</link><pubDate>Fri, 15 Aug 2008 16:40:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8869637</guid><dc:creator>Josh</dc:creator><description>&lt;p&gt;Thanks Simon,&lt;/p&gt;
&lt;p&gt;“I can’t really think of a convincing reason why one of these would be better over the other to be honest – I guess Josh’s approach means you could have different collections of commands (WebCommands, WindowsCommands, SomeOtherCommands), but I’ve never needed to do that. Any other reasons you can think of?”&lt;/p&gt;
&lt;p&gt;Imagine you write a logging component (generic example again) for use throughout your enterprise and you want to use stongly typed primitives (nice turn of phrase btw). You can’t know now all the possible entries that people would want to use. So the primitive itself lives next to the logging component itself but the instances of the primitives would live in a separate assembly per application that uses the component.&lt;/p&gt;</description></item><item><title>re: Strongly Typed Primitives</title><link>http://blogs.msdn.com/simonince/archive/2008/08/15/strongly-typed-primitives.aspx#8869651</link><pubDate>Fri, 15 Aug 2008 16:47:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8869651</guid><dc:creator>simonince</dc:creator><description>&lt;p&gt;@ Josh;&lt;/p&gt;
&lt;p&gt;I like it. In fact, come to think of it there are similarities to when I was building a navigation framework targeting both web and windows. I made a vague reference to this with my &amp;quot;Screen&amp;quot; class here;&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/simonince/archive/2008/06/16/wcsf-application-architecture-4-environment-abstraction.aspx"&gt;http://blogs.msdn.com/simonince/archive/2008/06/16/wcsf-application-architecture-4-environment-abstraction.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I forget exactly how it worked but I had to create different instances of the class because I wanted to use it to encapsulate information about how to actually navigate to a screen too - which obviously is very different in the web and windows worlds.&lt;/p&gt;
&lt;p&gt;Hmm.&lt;/p&gt;
&lt;p&gt;OK, so I think my approach is the version for beginners, yours is the posh one :-)&lt;/p&gt;
</description></item><item><title>Strongly Typed Primitives</title><link>http://blogs.msdn.com/simonince/archive/2008/08/15/strongly-typed-primitives.aspx#8869715</link><pubDate>Fri, 15 Aug 2008 17:15:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8869715</guid><dc:creator>DotNetKicks.com</dc:creator><description>&lt;p&gt;You've been kicked (a good thing) - Trackback from DotNetKicks.com&lt;/p&gt;
</description></item><item><title>re: Strongly Typed Primitives</title><link>http://blogs.msdn.com/simonince/archive/2008/08/15/strongly-typed-primitives.aspx#8870527</link><pubDate>Fri, 15 Aug 2008 22:45:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8870527</guid><dc:creator>MichaelGG</dc:creator><description>&lt;p&gt;You can also make it generic so everything can fit in a small static class:&lt;/p&gt;
&lt;p&gt;public static class Command&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;public static readonly Id&amp;lt;Command&amp;gt; Profile = (Id&amp;lt;Command&amp;gt;)&amp;quot;Profile&amp;quot;;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;public static readonly Id&amp;lt;Command&amp;gt; WebExecute = new (Id&amp;lt;Command&amp;gt;&amp;quot;WebExecute&amp;quot;;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;Now the type name is just a marker so you can do everything with a single class, and just pick the best name (Command versus CommandName). I posted the code I use here:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://www.atrevido.net/blog/2008/08/15/Typing+String+IDs.aspx"&gt;http://www.atrevido.net/blog/2008/08/15/Typing+String+IDs.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;(Although, if you don't care about performance and nullability issues, a class-based inheritance system may provide more benefits.)&lt;/p&gt;</description></item><item><title>re: Strongly Typed Primitives</title><link>http://blogs.msdn.com/simonince/archive/2008/08/15/strongly-typed-primitives.aspx#8876092</link><pubDate>Mon, 18 Aug 2008 11:13:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8876092</guid><dc:creator>simonince</dc:creator><description>&lt;p&gt;@ Michael;&lt;/p&gt;
&lt;p&gt;nice post, and good point. I think the only thing about using generics is that you can't use the class to store more information. So although Josh's example is for strings, I've used this approach to store a string name and a string URL together - which makes defining a generic to cover all situations difficult.&lt;/p&gt;
&lt;p&gt;Having said that, I totally agree in a lot of cases it would work.&lt;/p&gt;
&lt;p&gt;One minor point - I'm not sure I like casting to an Id&amp;lt;Command&amp;gt; - I'd always prefer the 'new Id&amp;lt;Command&amp;gt;(&amp;quot;WebExecute&amp;quot;)' syntax, as it seems more explicit. Just personal taste, perhaps!&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;
</description></item><item><title>re: Strongly Typed Primitives</title><link>http://blogs.msdn.com/simonince/archive/2008/08/15/strongly-typed-primitives.aspx#8876772</link><pubDate>Mon, 18 Aug 2008 19:33:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8876772</guid><dc:creator>MichaelGG</dc:creator><description>&lt;p&gt;Ah, yes, keeping multiple items would be a pain right now. More reason to lean on the .NET teams to add tuples as first class citizens :).&lt;/p&gt;</description></item></channel></rss>