<?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: Policy-based Design in D</title>
	<atom:link href="http://dblog.aldacron.net/2006/06/16/policy-based-design-in-d/feed/" rel="self" type="application/rss+xml" />
	<link>http://dblog.aldacron.net/2006/06/16/policy-based-design-in-d/</link>
	<description>News and Opinions Regarding the D Programming Language</description>
	<lastBuildDate>Fri, 20 Jan 2012 13:36:27 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Aldacron</title>
		<link>http://dblog.aldacron.net/2006/06/16/policy-based-design-in-d/comment-page-1/#comment-2539</link>
		<dc:creator>Aldacron</dc:creator>
		<pubDate>Sat, 03 Mar 2007 16:40:50 +0000</pubDate>
		<guid isPermaLink="false">http://dblog.aldacron.net/2006/06/16/policy-based-design-in-d/#comment-2539</guid>
		<description>&lt;i&gt;You said youâ€™re using this for singletons.
Can you provide a short example of that?&lt;/i&gt;

It&#039;s not really clear what the way I wrote it, but what I was referring to regarding Singletons was the declaration of the template type. Notice the two styles I used in the example:

&lt;blockquote&gt;
// one - templated subclass declaration
class GreetHost : Host!(GreetPolicy) { }

// two - declaration at instantiation
Host!(GreetPolicy) h = new Host!(GreetPolicy);
&lt;/blockquote&gt;

The first technique is similar to what I had been using to declare templated Singletons (i.e. class MySingletonClass : Singleton!(MySingletonClass) {}). There are a few different ways to declare Singletons. I might write a post on it. Scott Bilas gives an overview of a few different Singleton styles in a Game Programming Gems article he wrote, &lt;i&gt;An Automatic Singleton Utility&lt;/i&gt;, which is also available &lt;a href=&quot;http://www.drizzle.com/~scottb/publish/gpgems1_singleton.htm&quot; rel=&quot;nofollow&quot;&gt;online&lt;/a&gt;. It&#039;s C++ code, but can be translated to D with little difficulty.

&lt;i&gt;Also Iâ€™m still not sure when to prefer one global object over the singleton pattern, maybe you could write a bit about how you work with singletons in D and cover this? Iâ€™d find it very cool&lt;/i&gt;

This really boils down to a matter of personal taste. The Singleton pattern, as simple as it is, is likely the least understood and most abused pattern in the GoF book. Some people insist that &quot;globals are the root of all evil&quot; and use Singletons as a means to avoid them. Some people insist Singletons should only be used for objects of which there should only be one instance. Some people avoid them altogether. I honestly fall into the middle camp (only one instance of an object), since that&#039;s the problem the pattern is intended to solve. But to be honest, for I quite frequently just declare a struct with all static methods rather than using Singletons. It&#039;s the same effect. 

This is one of those cases where there really is more than one way to skin the cat. But I believe the circumstances of a project should dictate which technique to use and not the programmer&#039;s preference. For example, if I were writing a library for others to use I would try do reduce the number of global objects exposed to the user. Internally, it doesn&#039;t matter. But exposing globals outside of the library really can be evil, as they pollute the user&#039;s namespace and make the library more difficult to use. I would also be hesitant to use them in projects with large teams, since they increase the chance for error. But, I personally would never use a Singleton solely as a substitute for a global because that&#039;s not what the pattern is intended for.

As a general rule, anytime I have a manager class (GraphicsManager, InputManager, or whatever) I use a Singleton pattern (or the bastardized version I mentioned above -- structs with static methods). Beyond that, it&#039;s a case-by-case basis.</description>
		<content:encoded><![CDATA[<p><i>You said youâ€™re using this for singletons.<br />
Can you provide a short example of that?</i></p>
<p>It&#8217;s not really clear what the way I wrote it, but what I was referring to regarding Singletons was the declaration of the template type. Notice the two styles I used in the example:</p>
<blockquote><p>
// one &#8211; templated subclass declaration<br />
class GreetHost : Host!(GreetPolicy) { }</p>
<p>// two &#8211; declaration at instantiation<br />
Host!(GreetPolicy) h = new Host!(GreetPolicy);
</p></blockquote>
<p>The first technique is similar to what I had been using to declare templated Singletons (i.e. class MySingletonClass : Singleton!(MySingletonClass) {}). There are a few different ways to declare Singletons. I might write a post on it. Scott Bilas gives an overview of a few different Singleton styles in a Game Programming Gems article he wrote, <i>An Automatic Singleton Utility</i>, which is also available <a href="http://www.drizzle.com/~scottb/publish/gpgems1_singleton.htm" rel="nofollow">online</a>. It&#8217;s C++ code, but can be translated to D with little difficulty.</p>
<p><i>Also Iâ€™m still not sure when to prefer one global object over the singleton pattern, maybe you could write a bit about how you work with singletons in D and cover this? Iâ€™d find it very cool</i></p>
<p>This really boils down to a matter of personal taste. The Singleton pattern, as simple as it is, is likely the least understood and most abused pattern in the GoF book. Some people insist that &#8220;globals are the root of all evil&#8221; and use Singletons as a means to avoid them. Some people insist Singletons should only be used for objects of which there should only be one instance. Some people avoid them altogether. I honestly fall into the middle camp (only one instance of an object), since that&#8217;s the problem the pattern is intended to solve. But to be honest, for I quite frequently just declare a struct with all static methods rather than using Singletons. It&#8217;s the same effect. </p>
<p>This is one of those cases where there really is more than one way to skin the cat. But I believe the circumstances of a project should dictate which technique to use and not the programmer&#8217;s preference. For example, if I were writing a library for others to use I would try do reduce the number of global objects exposed to the user. Internally, it doesn&#8217;t matter. But exposing globals outside of the library really can be evil, as they pollute the user&#8217;s namespace and make the library more difficult to use. I would also be hesitant to use them in projects with large teams, since they increase the chance for error. But, I personally would never use a Singleton solely as a substitute for a global because that&#8217;s not what the pattern is intended for.</p>
<p>As a general rule, anytime I have a manager class (GraphicsManager, InputManager, or whatever) I use a Singleton pattern (or the bastardized version I mentioned above &#8212; structs with static methods). Beyond that, it&#8217;s a case-by-case basis.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Henning Hasemann</title>
		<link>http://dblog.aldacron.net/2006/06/16/policy-based-design-in-d/comment-page-1/#comment-2522</link>
		<dc:creator>Henning Hasemann</dc:creator>
		<pubDate>Fri, 02 Mar 2007 19:18:15 +0000</pubDate>
		<guid isPermaLink="false">http://dblog.aldacron.net/2006/06/16/policy-based-design-in-d/#comment-2522</guid>
		<description>You said you&#039;re using this for singletons.
Can you provide a short example of that?
Im still searching for a templating mechanism which lets me use the new operator instead of having to acces the instance property.

Also I&#039;m still not sure when to prefer one global object over the singleton pattern, maybe you could write a bit about how you work with singletons in D and cover this? I&#039;d find it very cool :-)</description>
		<content:encoded><![CDATA[<p>You said you&#8217;re using this for singletons.<br />
Can you provide a short example of that?<br />
Im still searching for a templating mechanism which lets me use the new operator instead of having to acces the instance property.</p>
<p>Also I&#8217;m still not sure when to prefer one global object over the singleton pattern, maybe you could write a bit about how you work with singletons in D and cover this? I&#8217;d find it very cool <img src='http://dblog.aldacron.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rohit Joshi</title>
		<link>http://dblog.aldacron.net/2006/06/16/policy-based-design-in-d/comment-page-1/#comment-88</link>
		<dc:creator>Rohit Joshi</dc:creator>
		<pubDate>Tue, 27 Jun 2006 19:38:40 +0000</pubDate>
		<guid isPermaLink="false">http://dblog.aldacron.net/2006/06/16/policy-based-design-in-d/#comment-88</guid>
		<description>Look at some of the articles I have posted on code projects which explains policy based design.

e.g
Generic Pool: Policy based design : http://www.codeproject.com/library/Generic_Pool_Design.asp

Queue Manager: Policy Based Design : http://www.codeproject.com/threads/Queue_Manager.asp

Memory Map Class : Policy Based Design: http://www.codeproject.com/file/Memory_Mapped_Class___PBD.asp</description>
		<content:encoded><![CDATA[<p>Look at some of the articles I have posted on code projects which explains policy based design.</p>
<p>e.g<br />
Generic Pool: Policy based design : <a href="http://www.codeproject.com/library/Generic_Pool_Design.asp" rel="nofollow">http://www.codeproject.com/library/Generic_Pool_Design.asp</a></p>
<p>Queue Manager: Policy Based Design : <a href="http://www.codeproject.com/threads/Queue_Manager.asp" rel="nofollow">http://www.codeproject.com/threads/Queue_Manager.asp</a></p>
<p>Memory Map Class : Policy Based Design: <a href="http://www.codeproject.com/file/Memory_Mapped_Class___PBD.asp" rel="nofollow">http://www.codeproject.com/file/Memory_Mapped_Class___PBD.asp</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Policy-based Free List Â» News and Opinions of the Digital Mars D Programming Language</title>
		<link>http://dblog.aldacron.net/2006/06/16/policy-based-design-in-d/comment-page-1/#comment-79</link>
		<dc:creator>Policy-based Free List Â» News and Opinions of the Digital Mars D Programming Language</dc:creator>
		<pubDate>Fri, 23 Jun 2006 08:10:21 +0000</pubDate>
		<guid isPermaLink="false">http://dblog.aldacron.net/2006/06/16/policy-based-design-in-d/#comment-79</guid>
		<description>[...] One of the reasons I was experimenting with policies earlier (1, 2) was to implement a policy-based free list I had seen in Game Programming Gems 5 in an article by Nathan Mefford of Firaxis (1.11 Improving Freelists with Policy Based Design). I&#8217;m fairly satisfied with the implementation I put together. [...]</description>
		<content:encoded><![CDATA[<p>[...] One of the reasons I was experimenting with policies earlier (1, 2) was to implement a policy-based free list I had seen in Game Programming Gems 5 in an article by Nathan Mefford of Firaxis (1.11 Improving Freelists with Policy Based Design). I&#8217;m fairly satisfied with the implementation I put together. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: More on Policies Â» News and Opinions of the Digital Mars D Programming Language</title>
		<link>http://dblog.aldacron.net/2006/06/16/policy-based-design-in-d/comment-page-1/#comment-63</link>
		<dc:creator>More on Policies Â» News and Opinions of the Digital Mars D Programming Language</dc:creator>
		<pubDate>Mon, 19 Jun 2006 00:53:33 +0000</pubDate>
		<guid isPermaLink="false">http://dblog.aldacron.net/2006/06/16/policy-based-design-in-d/#comment-63</guid>
		<description>[...] A limitation that I quickly ran into with my attempt at templated, inherited policies was D&#8217;s lack of support for multiple inheritance. Normally, I have no need for MI, but this is one case where it would have been neat to have. As long as a class uses one policy, the templated, inherited approach is good enough. To solve the multiple policy problem, I went with templated containment: [...]</description>
		<content:encoded><![CDATA[<p>[...] A limitation that I quickly ran into with my attempt at templated, inherited policies was D&#8217;s lack of support for multiple inheritance. Normally, I have no need for MI, but this is one case where it would have been neat to have. As long as a class uses one policy, the templated, inherited approach is good enough. To solve the multiple policy problem, I went with templated containment: [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: D Tip: Policy-based Design Â» News, opinions, articles, tips &#38; tricks on game development with an Indie twist.</title>
		<link>http://dblog.aldacron.net/2006/06/16/policy-based-design-in-d/comment-page-1/#comment-52</link>
		<dc:creator>D Tip: Policy-based Design Â» News, opinions, articles, tips &#38; tricks on game development with an Indie twist.</dc:creator>
		<pubDate>Sun, 18 Jun 2006 12:34:30 +0000</pubDate>
		<guid isPermaLink="false">http://dblog.aldacron.net/2006/06/16/policy-based-design-in-d/#comment-52</guid>
		<description>[...] Policies are a powerful technique to use for some class designs. It&#8217;s a well known solution in C++, but someone coming to D may run into wrinkles using certain variations of the technique. I recently posted two entries (1, 2) on my D blog showing two ways to implement policies in D. Templates in D are similar to C++ templates, but there are enough differences that some practice may be required to get a feel for them. For more info on D templates, read the Templates page of the D Programming Language docs and Walter Bright&#8217;s article, Templates Revisited. [...]</description>
		<content:encoded><![CDATA[<p>[...] Policies are a powerful technique to use for some class designs. It&#8217;s a well known solution in C++, but someone coming to D may run into wrinkles using certain variations of the technique. I recently posted two entries (1, 2) on my D blog showing two ways to implement policies in D. Templates in D are similar to C++ templates, but there are enough differences that some practice may be required to get a feel for them. For more info on D templates, read the Templates page of the D Programming Language docs and Walter Bright&#8217;s article, Templates Revisited. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aldacron</title>
		<link>http://dblog.aldacron.net/2006/06/16/policy-based-design-in-d/comment-page-1/#comment-51</link>
		<dc:creator>Aldacron</dc:creator>
		<pubDate>Sat, 17 Jun 2006 14:36:07 +0000</pubDate>
		<guid isPermaLink="false">http://dblog.aldacron.net/2006/06/16/policy-based-design-in-d/#comment-51</guid>
		<description>I implemented multiple policies without using mixins by making the templated policies members and instantiating them in a constructor. That&#039;s actually my next post.</description>
		<content:encoded><![CDATA[<p>I implemented multiple policies without using mixins by making the templated policies members and instantiating them in a constructor. That&#8217;s actually my next post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: h3r3tic</title>
		<link>http://dblog.aldacron.net/2006/06/16/policy-based-design-in-d/comment-page-1/#comment-50</link>
		<dc:creator>h3r3tic</dc:creator>
		<pubDate>Sat, 17 Jun 2006 13:17:08 +0000</pubDate>
		<guid isPermaLink="false">http://dblog.aldacron.net/2006/06/16/policy-based-design-in-d/#comment-50</guid>
		<description>Hey Mike,
you might want to use mixins and interfaces for it, since you won&#039;t be able to inherit from more than one class.. you could mix policies in after all :)</description>
		<content:encoded><![CDATA[<p>Hey Mike,<br />
you might want to use mixins and interfaces for it, since you won&#8217;t be able to inherit from more than one class.. you could mix policies in after all <img src='http://dblog.aldacron.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>

