<?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/"
	xmlns:series="http://organizeseries.com/"
		>
<channel>
	<title>Comments on: The Registry Pattern Reexamined</title>
	<atom:link href="http://www.brandonsavage.net/the-registry-pattern-reexamined/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brandonsavage.net/the-registry-pattern-reexamined/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-registry-pattern-reexamined</link>
	<description>The personal blog of Brandon Savage. Contains entries of a personal and professional nature focusing on PHP, Apple, LAMP, MySQL and Washington, DC.</description>
	<lastBuildDate>Wed, 15 May 2013 14:54:51 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.2-alpha</generator>
	<item>
		<title>By: Ahmed Shreef</title>
		<link>http://www.brandonsavage.net/the-registry-pattern-reexamined/#comment-3281</link>
		<dc:creator>Ahmed Shreef</dc:creator>
		<pubDate>Wed, 14 Apr 2010 01:08:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=1221#comment-3281</guid>
		<description><![CDATA[using a setter with optional parameter can allow you to Inject your Dependencies and use Registry at the same time.

public function setDb($obj=null) {
    if ( $obj !== null ) {
     return $this-&gt;_db = $obj;
    }

    return $this-&gt;_db = Registry::get(&#039;db&#039;);
} 

you can write unit tests for this class simply this way and you are still using Registry.]]></description>
		<content:encoded><![CDATA[<p>using a setter with optional parameter can allow you to Inject your Dependencies and use Registry at the same time.</p>
<p>public function setDb($obj=null) {<br />
    if ( $obj !== null ) {<br />
     return $this-&gt;_db = $obj;<br />
    }</p>
<p>    return $this-&gt;_db = Registry::get(&#8216;db&#8217;);<br />
} </p>
<p>you can write unit tests for this class simply this way and you are still using Registry.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tibo Beijen</title>
		<link>http://www.brandonsavage.net/the-registry-pattern-reexamined/#comment-3140</link>
		<dc:creator>Tibo Beijen</dc:creator>
		<pubDate>Fri, 02 Apr 2010 07:56:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=1221#comment-3140</guid>
		<description><![CDATA[As a rule of thumb I use a registry only to store and retreive objects that are read-only (config) or &#039;use-only&#039; (db, log, factories).

When you use a registry as a &#039;convenient tool&#039; to transport objects (holding data that might change throughout code execution) from A to B, alarm bells should start to ring...]]></description>
		<content:encoded><![CDATA[<p>As a rule of thumb I use a registry only to store and retreive objects that are read-only (config) or &#8216;use-only&#8217; (db, log, factories).</p>
<p>When you use a registry as a &#8216;convenient tool&#8217; to transport objects (holding data that might change throughout code execution) from A to B, alarm bells should start to ring&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jiri Fornous</title>
		<link>http://www.brandonsavage.net/the-registry-pattern-reexamined/#comment-3113</link>
		<dc:creator>Jiri Fornous</dc:creator>
		<pubDate>Mon, 29 Mar 2010 07:37:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=1221#comment-3113</guid>
		<description><![CDATA[I think nobody has mentioned the main reason why registry pattern is used - it&#039;s because of state serialization (mostly on model). It&#039;s very easy to travers all your objects created without knowing them. Since there is always a way how to register objects and also follow good programming practice (DI).]]></description>
		<content:encoded><![CDATA[<p>I think nobody has mentioned the main reason why registry pattern is used &#8211; it&#8217;s because of state serialization (mostly on model). It&#8217;s very easy to travers all your objects created without knowing them. Since there is always a way how to register objects and also follow good programming practice (DI).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Les</title>
		<link>http://www.brandonsavage.net/the-registry-pattern-reexamined/#comment-3099</link>
		<dc:creator>Les</dc:creator>
		<pubDate>Sat, 27 Mar 2010 10:43:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=1221#comment-3099</guid>
		<description><![CDATA[@Miles

That is very true; the Registry should only be used in application code.

I made provision for passing objects along the layers in my own framework so I can easily begin a new application without useing Registry at all.

@Leonard

Very true and that is being openly abusive of the Registry design, developers with little or no understand should just step aside IMHO.]]></description>
		<content:encoded><![CDATA[<p>@Miles</p>
<p>That is very true; the Registry should only be used in application code.</p>
<p>I made provision for passing objects along the layers in my own framework so I can easily begin a new application without useing Registry at all.</p>
<p>@Leonard</p>
<p>Very true and that is being openly abusive of the Registry design, developers with little or no understand should just step aside IMHO.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Miles Johnson</title>
		<link>http://www.brandonsavage.net/the-registry-pattern-reexamined/#comment-3094</link>
		<dc:creator>Miles Johnson</dc:creator>
		<pubDate>Sat, 27 Mar 2010 03:58:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=1221#comment-3094</guid>
		<description><![CDATA[There are many different ways to use the Registry pattern. But if I want to retrieve an instance of an object in multiple places and have them all update each other, than I would use a Registry.

The Registry however should not run the core/framework of your App, it should simply be a convenience.]]></description>
		<content:encoded><![CDATA[<p>There are many different ways to use the Registry pattern. But if I want to retrieve an instance of an object in multiple places and have them all update each other, than I would use a Registry.</p>
<p>The Registry however should not run the core/framework of your App, it should simply be a convenience.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://www.brandonsavage.net/the-registry-pattern-reexamined/#comment-3093</link>
		<dc:creator>James</dc:creator>
		<pubDate>Fri, 26 Mar 2010 23:13:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=1221#comment-3093</guid>
		<description><![CDATA[@Matic: Globals are actually considered an anti-pattern (http://c2.com/cgi/wiki?GlobalVariable). There are a few very good reasons not to use them:

First, in PHP, there is nothing protecting globals from being changed. Some well meaning, but unknowing, developer might not realize that the &quot;cache&quot; global is already being used. They assign a different value to the variable and are happily on their way. Now you have a bug that is caused because of their code, but manifests itself in yours. These can be brutal. 

Second, global state hides dependencies. I usually compare it to &quot;f(X) = Y&quot;. When you plug in X, you should always get Y as the return value. If changing a global affects the result of a function, then it is really a hidden argument. Suddenly, you have to know about the inner workings of the method to understand why f(X) now returns Z. Really, your method is f(X, GLOBAL) = Y. This can be really become a problem when trying to do Test Driven Development. Globals make writing tests a pain in the arse. 

Anyway, I recommend taking a look at Misko Hevery&#039;s blog (http://misko.hevery.com/). He has written quite a bit about testability and dependency injection. Suffice to say, he is an avid opponent of Globals (and Singletons).]]></description>
		<content:encoded><![CDATA[<p>@Matic: Globals are actually considered an anti-pattern (<a href="http://c2.com/cgi/wiki?GlobalVariable" rel="nofollow">http://c2.com/cgi/wiki?GlobalVariable</a>). There are a few very good reasons not to use them:</p>
<p>First, in PHP, there is nothing protecting globals from being changed. Some well meaning, but unknowing, developer might not realize that the &#8220;cache&#8221; global is already being used. They assign a different value to the variable and are happily on their way. Now you have a bug that is caused because of their code, but manifests itself in yours. These can be brutal. </p>
<p>Second, global state hides dependencies. I usually compare it to &#8220;f(X) = Y&#8221;. When you plug in X, you should always get Y as the return value. If changing a global affects the result of a function, then it is really a hidden argument. Suddenly, you have to know about the inner workings of the method to understand why f(X) now returns Z. Really, your method is f(X, GLOBAL) = Y. This can be really become a problem when trying to do Test Driven Development. Globals make writing tests a pain in the arse. </p>
<p>Anyway, I recommend taking a look at Misko Hevery&#8217;s blog (<a href="http://misko.hevery.com/" rel="nofollow">http://misko.hevery.com/</a>). He has written quite a bit about testability and dependency injection. Suffice to say, he is an avid opponent of Globals (and Singletons).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Flavius Stef</title>
		<link>http://www.brandonsavage.net/the-registry-pattern-reexamined/#comment-3092</link>
		<dc:creator>Flavius Stef</dc:creator>
		<pubDate>Fri, 26 Mar 2010 23:07:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=1221#comment-3092</guid>
		<description><![CDATA[1) I would argue that adding setter methods to the Registry solves the testing problem. Running Registry::setDatabase($mock) prior to the code being tested takes care of the coupling.

2) If not using a DI framework, but a ServiceLocator instead, the Registry is a proper fit for all of the configuration-wide objects (database connection, logger, configuration parameters etc.)]]></description>
		<content:encoded><![CDATA[<p>1) I would argue that adding setter methods to the Registry solves the testing problem. Running Registry::setDatabase($mock) prior to the code being tested takes care of the coupling.</p>
<p>2) If not using a DI framework, but a ServiceLocator instead, the Registry is a proper fit for all of the configuration-wide objects (database connection, logger, configuration parameters etc.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://www.brandonsavage.net/the-registry-pattern-reexamined/#comment-3091</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Fri, 26 Mar 2010 20:20:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=1221#comment-3091</guid>
		<description><![CDATA[I understand your pov but how would you handle global configuration and db connections passing it around trough all THE objects seems not very handy]]></description>
		<content:encoded><![CDATA[<p>I understand your pov but how would you handle global configuration and db connections passing it around trough all THE objects seems not very handy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leonard Dronkers</title>
		<link>http://www.brandonsavage.net/the-registry-pattern-reexamined/#comment-3090</link>
		<dc:creator>Leonard Dronkers</dc:creator>
		<pubDate>Fri, 26 Mar 2010 19:26:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=1221#comment-3090</guid>
		<description><![CDATA[I have seen abuse of the (static/global) registry pattern where stuff is just dumped in there. And then picked up at will(in library code for example...) Not a good practice. 

That said, it can come in handy... just a matter of proper usage.]]></description>
		<content:encoded><![CDATA[<p>I have seen abuse of the (static/global) registry pattern where stuff is just dumped in there. And then picked up at will(in library code for example&#8230;) Not a good practice. </p>
<p>That said, it can come in handy&#8230; just a matter of proper usage.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Les</title>
		<link>http://www.brandonsavage.net/the-registry-pattern-reexamined/#comment-3088</link>
		<dc:creator>Les</dc:creator>
		<pubDate>Fri, 26 Mar 2010 18:18:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=1221#comment-3088</guid>
		<description><![CDATA[I still use Registry today however I tend to use it indirectly, for example this way

...
public function getConnection() {
if( is_null( $this -&gt; db ) ) {
$this -&gt; db = Registry::get( &#039;db&#039; );
}
return $this -&gt; db;
}
...

You now have a default connection or use a setter to set a different one. Too many applications use DI when that is over the top IMHO; do remember the wrong tool can do just as much damage.]]></description>
		<content:encoded><![CDATA[<p>I still use Registry today however I tend to use it indirectly, for example this way</p>
<p>&#8230;<br />
public function getConnection() {<br />
if( is_null( $this -&gt; db ) ) {<br />
$this -&gt; db = Registry::get( &#8216;db&#8217; );<br />
}<br />
return $this -&gt; db;<br />
}<br />
&#8230;</p>
<p>You now have a default connection or use a setter to set a different one. Too many applications use DI when that is over the top IMHO; do remember the wrong tool can do just as much damage.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dwayne Holmberg</title>
		<link>http://www.brandonsavage.net/the-registry-pattern-reexamined/#comment-3086</link>
		<dc:creator>Dwayne Holmberg</dc:creator>
		<pubDate>Fri, 26 Mar 2010 17:27:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=1221#comment-3086</guid>
		<description><![CDATA[The registry love going around lately has been disturbing me. I&#039;ve used it extensively in the past and ran into a couple of other problems as well:

1) you don&#039;t know what is using items pulled from the registry, so you don&#039;t know where modifications to those might be being made. It&#039;s a whole new level of spaghetti that makes debugging hell.

2) using keys to reference items in the registry becomes problematic because they are easier to add then they are to document. (For a similar reason, I prefer explicit setters to option arrays, which is another religious debate.)

Registry is seductive because it&#039;s easy right now, while you&#039;re in the code, but it&#039;s a short term payoff.]]></description>
		<content:encoded><![CDATA[<p>The registry love going around lately has been disturbing me. I&#8217;ve used it extensively in the past and ran into a couple of other problems as well:</p>
<p>1) you don&#8217;t know what is using items pulled from the registry, so you don&#8217;t know where modifications to those might be being made. It&#8217;s a whole new level of spaghetti that makes debugging hell.</p>
<p>2) using keys to reference items in the registry becomes problematic because they are easier to add then they are to document. (For a similar reason, I prefer explicit setters to option arrays, which is another religious debate.)</p>
<p>Registry is seductive because it&#8217;s easy right now, while you&#8217;re in the code, but it&#8217;s a short term payoff.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jake Smith</title>
		<link>http://www.brandonsavage.net/the-registry-pattern-reexamined/#comment-3085</link>
		<dc:creator>Jake Smith</dc:creator>
		<pubDate>Fri, 26 Mar 2010 13:55:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=1221#comment-3085</guid>
		<description><![CDATA[I&#039;m a fan of DI and usually have core objects stored (DB, Log, Session, etc).  I can understand why newer developers can fall in love with the Registry Pattern....&quot;I can access any of my objects....at anytime? sign me up!&quot;.

Great post on why you shouldn&#039;t &quot;overuse&quot; Registry and with alternative solutions.]]></description>
		<content:encoded><![CDATA[<p>I&#8217;m a fan of DI and usually have core objects stored (DB, Log, Session, etc).  I can understand why newer developers can fall in love with the Registry Pattern&#8230;.&#8221;I can access any of my objects&#8230;.at anytime? sign me up!&#8221;.</p>
<p>Great post on why you shouldn&#8217;t &#8220;overuse&#8221; Registry and with alternative solutions.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matthew Weier O'Phinney</title>
		<link>http://www.brandonsavage.net/the-registry-pattern-reexamined/#comment-3082</link>
		<dc:creator>Matthew Weier O'Phinney</dc:creator>
		<pubDate>Fri, 26 Mar 2010 13:21:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=1221#comment-3082</guid>
		<description><![CDATA[The Registry pattern you speak of here is better termed a Global Registry or Static Registry. 

You can also have a Registry that is neither global nor static, and which is passed around between objects or which acts as an internal registry for an object with many collaborators. We use the pattern in Zend Framework on Zend_Application_Bootstrap, which uses a Registry internally to keep track of bootstrapped resources for later use.]]></description>
		<content:encoded><![CDATA[<p>The Registry pattern you speak of here is better termed a Global Registry or Static Registry. </p>
<p>You can also have a Registry that is neither global nor static, and which is passed around between objects or which acts as an internal registry for an object with many collaborators. We use the pattern in Zend Framework on Zend_Application_Bootstrap, which uses a Registry internally to keep track of bootstrapped resources for later use.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fqqdk</title>
		<link>http://www.brandonsavage.net/the-registry-pattern-reexamined/#comment-3081</link>
		<dc:creator>fqqdk</dc:creator>
		<pubDate>Fri, 26 Mar 2010 12:46:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=1221#comment-3081</guid>
		<description><![CDATA[yay :) good to see another fellow coder on this side of the religious schism :D]]></description>
		<content:encoded><![CDATA[<p>yay :) good to see another fellow coder on this side of the religious schism :D</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matic</title>
		<link>http://www.brandonsavage.net/the-registry-pattern-reexamined/#comment-3080</link>
		<dc:creator>Matic</dc:creator>
		<pubDate>Fri, 26 Mar 2010 12:13:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.brandonsavage.net/?p=1221#comment-3080</guid>
		<description><![CDATA[PHP already has a built in registry, it&#039;s $GLOBALS and I really like it because it makes code simpler. To store a value in cache I simply use:

$GLOBALS[&#039;cache&#039;]-&gt;set($key, $value); 

I use similar commands for DB access, sending debug info to Firebug, current user data (language, locale, timezone, location, ...) and similar. Basically, stuff I need easily accessible from everywhere.

It&#039;s good for me and has never caused me any problems. It&#039;s part of the framework I&#039;ve created. It&#039;s what frameworks are for.

I don&#039;t understand your POV.]]></description>
		<content:encoded><![CDATA[<p>PHP already has a built in registry, it&#8217;s $GLOBALS and I really like it because it makes code simpler. To store a value in cache I simply use:</p>
<p>$GLOBALS['cache']-&gt;set($key, $value); </p>
<p>I use similar commands for DB access, sending debug info to Firebug, current user data (language, locale, timezone, location, &#8230;) and similar. Basically, stuff I need easily accessible from everywhere.</p>
<p>It&#8217;s good for me and has never caused me any problems. It&#8217;s part of the framework I&#8217;ve created. It&#8217;s what frameworks are for.</p>
<p>I don&#8217;t understand your POV.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic (Feed is rejected)
Page Caching using disk: enhanced (User agent is rejected)
Object Caching 644/664 objects using apc
Content Delivery Network via Amazon Web Services: S3: brandonsavage-net-files.s3.amazonaws.com

 Served from: www.brandonsavage.net @ 2013-05-18 12:10:10 by W3 Total Cache -->