<?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: Singletons in PHP</title>
	<atom:link href="http://blog.endelo.com/2009/06/30/singletons-in-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.endelo.com/2009/06/30/singletons-in-php/</link>
	<description>Effectively achieving things people actually care about</description>
	<lastBuildDate>Tue, 02 Mar 2010 19:00:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: John</title>
		<link>http://blog.endelo.com/2009/06/30/singletons-in-php/comment-page-1/#comment-33</link>
		<dc:creator>John</dc:creator>
		<pubDate>Tue, 02 Mar 2010 19:00:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.endelo.com/?p=100#comment-33</guid>
		<description>Glad I could respond so quickly to you! Gerard might not be too pleased about my response time to him though :D. 

To address your statement, it&#039;s not so much about how unique each individual singleton is, but rather about the duplication of code used to simply implement the logic behind instantiating a singleton in the first place. Consider the concept of DRY as it applies to minimizing duplication of logic and, where possible, reducing boilerplate code. While you&#039;re database class will hold very different methods and fields than your session singleton, they both share the core logic of creating a single instance of themselves through a private constructor called by a static initializer: this is where abstraction and centralization of code would be most useful. 

Does that make sense? I enjoy conversations like these :)</description>
		<content:encoded><![CDATA[<p>Glad I could respond so quickly to you! Gerard might not be too pleased about my response time to him though <img src='http://blog.endelo.com/wp-content/plugins/tango-smilies/tango/face-smile-big.png' alt=':D' class='wp-smiley' /> . </p>
<p>To address your statement, it&#8217;s not so much about how unique each individual singleton is, but rather about the duplication of code used to simply implement the logic behind instantiating a singleton in the first place. Consider the concept of DRY as it applies to minimizing duplication of logic and, where possible, reducing boilerplate code. While you&#8217;re database class will hold very different methods and fields than your session singleton, they both share the core logic of creating a single instance of themselves through a private constructor called by a static initializer: this is where abstraction and centralization of code would be most useful. </p>
<p>Does that make sense? I enjoy conversations like these <img src='http://blog.endelo.com/wp-content/plugins/tango-smilies/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chris.</title>
		<link>http://blog.endelo.com/2009/06/30/singletons-in-php/comment-page-1/#comment-32</link>
		<dc:creator>chris.</dc:creator>
		<pubDate>Tue, 02 Mar 2010 13:56:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.endelo.com/?p=100#comment-32</guid>
		<description>Thanks for the quick answer!

I actually use the Singleton classes for the Database connection, Logger, Debugger, Session manager and Current User. All those instances should be unique around the whole application so I guess this is &quot;ok&quot; ;-)
Any advice or comment on this ?</description>
		<content:encoded><![CDATA[<p>Thanks for the quick answer!</p>
<p>I actually use the Singleton classes for the Database connection, Logger, Debugger, Session manager and Current User. All those instances should be unique around the whole application so I guess this is &#8220;ok&#8221; <img src='http://blog.endelo.com/wp-content/plugins/tango-smilies/tango/face-wink.png' alt=';-)' class='wp-smiley' /><br />
Any advice or comment on this ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://blog.endelo.com/2009/06/30/singletons-in-php/comment-page-1/#comment-31</link>
		<dc:creator>John</dc:creator>
		<pubDate>Mon, 01 Mar 2010 17:33:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.endelo.com/?p=100#comment-31</guid>
		<description>@Gerard: Thanks, I appreciate it! True, it may not be a requirement for you, and it may even make things more difficult on you as a developer, but I can definitely rationalize the need to only ever allow one alias: at the very least, it would lessen calls to getInstance((), make it easier for threading (locking only one alias), reduce references (trivial amount of memory, I know ;) ), and maybe the most practical, clean up your code! :)

@Chris: Certainly, you can absolutely extract out your public methods in the DB_Connection class into an Interface, and yes, it would be helpful - for DB_Connection. However, that doesn&#039;t really get you any wins in regards to encapsulating the logic germane to the Singleton pattern itself (#__construct and #getInstance, and the $instance field). This was what I was talking about in that it rather sucks to have to re-implement this boilerplate code every time you need a Singleton. Now, that being said, hopefully you&#039;re not going to be using too many Singletons in your code anyway, but that&#039;s tangential :). Thanks for the comment!</description>
		<content:encoded><![CDATA[<p>@Gerard: Thanks, I appreciate it! True, it may not be a requirement for you, and it may even make things more difficult on you as a developer, but I can definitely rationalize the need to only ever allow one alias: at the very least, it would lessen calls to getInstance((), make it easier for threading (locking only one alias), reduce references (trivial amount of memory, I know <img src='http://blog.endelo.com/wp-content/plugins/tango-smilies/tango/face-wink.png' alt=';)' class='wp-smiley' />  ), and maybe the most practical, clean up your code! <img src='http://blog.endelo.com/wp-content/plugins/tango-smilies/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>
<p>@Chris: Certainly, you can absolutely extract out your public methods in the DB_Connection class into an Interface, and yes, it would be helpful &#8211; for DB_Connection. However, that doesn&#8217;t really get you any wins in regards to encapsulating the logic germane to the Singleton pattern itself (#__construct and #getInstance, and the $instance field). This was what I was talking about in that it rather sucks to have to re-implement this boilerplate code every time you need a Singleton. Now, that being said, hopefully you&#8217;re not going to be using too many Singletons in your code anyway, but that&#8217;s tangential <img src='http://blog.endelo.com/wp-content/plugins/tango-smilies/tango/face-smile.png' alt=':)' class='wp-smiley' /> . Thanks for the comment!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chris.</title>
		<link>http://blog.endelo.com/2009/06/30/singletons-in-php/comment-page-1/#comment-30</link>
		<dc:creator>chris.</dc:creator>
		<pubDate>Mon, 01 Mar 2010 17:18:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.endelo.com/?p=100#comment-30</guid>
		<description>Hi,

Couldn&#039;t we define an interface declaring connect and query methods to be used ? Might be useful sometimes</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Couldn&#8217;t we define an interface declaring connect and query methods to be used ? Might be useful sometimes</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gerard</title>
		<link>http://blog.endelo.com/2009/06/30/singletons-in-php/comment-page-1/#comment-22</link>
		<dc:creator>Gerard</dc:creator>
		<pubDate>Fri, 20 Nov 2009 05:50:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.endelo.com/?p=100#comment-22</guid>
		<description>Good post, although I enjoyed the one on JavaScript caching more. I&#039;m not sure I agree with your statement that a purpose of Singletons is also to have only one alias; at least in Java, it&#039;s a common practice to have multiple declarations, as long as they reference the same object.

Either way, good post John. I&#039;ve already bookmarked this blog and sent you out to 20 of my programming friends. :)</description>
		<content:encoded><![CDATA[<p>Good post, although I enjoyed the one on JavaScript caching more. I&#8217;m not sure I agree with your statement that a purpose of Singletons is also to have only one alias; at least in Java, it&#8217;s a common practice to have multiple declarations, as long as they reference the same object.</p>
<p>Either way, good post John. I&#8217;ve already bookmarked this blog and sent you out to 20 of my programming friends. <img src='http://blog.endelo.com/wp-content/plugins/tango-smilies/tango/face-smile.png' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->