News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Paul Jones:
The Difference Between Factories, Registries, and Service Locators
December 03, 2013 @ 10:55:09

In his past few posts Paul Jones has been looking at dependency injection versus service locators. In this new post he continues on the topic comparing three methods for working with objects - factories, registries and service locators.

In last week's episode of this unexpected series, I said, "Go ahead and use Service Locator, but make sure each Locator contains only one type of object. This condition of restraint will keep a single locator from becoming a menace." [...] The "only one type of object" constraint generated some discussion regarding factories and registries. [...] The differences between factories, registries, and containers (both service locators and dependency injection containers) can be subtle and hard to grasp at first. Here's how I keep them straight.

He breaks them down with a simple definition for each related to how the object is created and its intended purpose. He also includes an example of a service locator he's created and a snippet of example code showing it in use.

Again, I must stress: Service locators can easily get out of control. If you can avoid using a service locator, you should.
0 comments voice your opinion now!
factory servicelocator registry difference example code

Link: http://paul-m-jones.com/archives/4800

blog comments powered by Disqus

Similar Posts

Dave Marshall's Blog: ZFSnippets.com - Zend Framework Code Snippets

SitePoint Blog: Book Release - "PHP Master: Write Cutting-Edge PHP Code"

Padraic Brady's Blog: Zend Framework Blog Tutorial - Part 7: Authorisation with Zend_Acl & Styling

Maarten Balliauw's Blog: Windows Azure Diagnostics in PHP

Pádraic Brady's Blog: RESTful Web Services with Zend Framework


Community Events

Don't see your event here?
Let us know!


community api podcast symfony opinion part2 conference laravel php7 introduction series interview list language framework application project composer yii2 example

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework