<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title>PHPDeveloper.org</title>
    <link>http://www.phpdeveloper.org</link>
    <description>Up-to-the Minute PHP News, views and community</description>
    <language>en-us</language>
    <pubDate>Wed, 23 May 2012 04:35:14 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Charles Sprayberry's Blog: DI and global state]]></title>
      <guid>http://www.phpdeveloper.org/news/17470</guid>
      <link>http://www.phpdeveloper.org/news/17470</link>
      <description><![CDATA[<p>
In response to some of the comments made on his <a href="http://phpdeveloper.org/news/17457">previous post</a> about why you should use dependency injection in your applications, <i>Charles Sprayberry</i> is <a href="http://cspray.github.com/2012/01/29/DI-and-global-state.html">back with some more concrete examples</a> showing how it all works with some code to back it up.
</p>
<blockquote>
To help better explain each of the three aspects of DI I discussed in the previous article I'll be going over each more thoroughly and with those code examples requested. I'll be going through each point one at a time as the explanations will likely be of some length compared to the original post.
</blockquote>
<p>
He starts with the "villain" of the story - the Singleton design pattern, a difficult to test method that lulls you into thinking you're not in the global scope. He talks about the problem of using this approach and how the <a href="http://sourcemaking.com/design_patterns/factory_method">Factory</a> design pattern can be used to create an alternative. He changes up the example to create a "DbTableFactory" class that can be used to create the objects needed - in this case a "UserTable" object with the connection injected into it at construct time.
</p>]]></description>
      <pubDate>Tue, 31 Jan 2012 09:24:47 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPMaster.com: Understanding the Factory Method Design Pattern]]></title>
      <guid>http://www.phpdeveloper.org/news/17272</guid>
      <link>http://www.phpdeveloper.org/news/17272</link>
      <description><![CDATA[<p>
On PHPMaster.com today there's a new design pattern-focused that introduces you to using the <a href="http://phpmaster.com/understanding-the-factory-method-design-pattern/">Factory method</a> to create new objects on the fly.
</p>
<blockquote>
The Factory Method pattern is a design pattern used to define a runtime interface for creating an object. It's called a factory because it creates various types of objects without necessarily knowing what kind of object it creates or how to create it.
</blockquote>
<p>
Code is included showing how to make creating "Product_*" classes as simple as calling a "build()" method with the type. A slightly more complex situation is also included - building factories inside of factory methods. For more about the Factory design pattern, check out <a href="http://en.wikipedia.org/wiki/Factory_method_pattern">its Wikipedia page</a> (that includes some common uses and some pitfalls to watch out for).
</p>]]></description>
      <pubDate>Fri, 16 Dec 2011 12:15:54 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Play nice when extending Exception]]></title>
      <guid>http://www.phpdeveloper.org/news/16397</guid>
      <link>http://www.phpdeveloper.org/news/16397</link>
      <description><![CDATA[<p>
<i>Lukas Smith</i> <a href="http://pooteeweet.org/blog/0/1932#m1932">has a suggestion</a> for developers out there who get the idea to start messing with the order of the parameters of PHP objects/methods - play nice. His example is specifically with Exceptions.
</p>
<blockquote>
This is just a short follow up to a recent tweet of mine. I have seen this repeatedly happen, even to top notch and usually very careful developers (*). I am not sure why this mistake happens so frequently, but quite often you see code that changes the parameter order for custom Exception constructors. I guess it's mostly because in these cases the developer wants to pass some magic parameters that contain the message (and potentially also the code). 
</blockquote>
<p>
He recommends that, if you really do need to change something like the order of the parameters, use something like a <a href="http://en.wikipedia.org/wiki/Factory_method_pattern">factory</a> to handle the reorganization for you.
</p>]]></description>
      <pubDate>Mon, 30 May 2011 09:48:29 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Zend Developer Zone: Design Patterns I Hate]]></title>
      <guid>http://www.phpdeveloper.org/news/16354</guid>
      <link>http://www.phpdeveloper.org/news/16354</link>
      <description><![CDATA[<p>
On the Zend Developer Zone today there's a new post from <i>Keith Casey</i> about some of the <a href="http://devzone.zend.com/article/14938-Design-Patterns-I-Hate">design patterns he hates</a> - ones that are misused too often and have become more of a "worst practice" at times than others.
</p>
<blockquote>
To be clear, I think <a href="http://devzone.zend.com/article/14003-My-Favorite-Design-Patterns">Design Patterns have their place</a>. When used properly, they can make our lives easier and our code better. When they're misused - "<a href="http://en.wikipedia.org/wiki/Law_of_the_instrument">If the only tool you have is a hammer..</a>" - then they can become the bane of our existence. Unfortunately, some Design Patterns seem more susceptible to this than others. So maybe this is less "design patterns I hate" and more of "design patterns that have been abused beyond all sense of reason"... I'll let you decide.
</blockquote>
<p>
He has three of the most commonly misused design patterns in his list. Anyone who has looked into using patterns in their applications will recognize them:
</p>
<ul>
<li>Active Record
<li>Factory
<li>Singleton
</ul>
<p>
For each, he describes some of the bad implementations he's seen and notes that, while these are commonly abused, they can still be redeemed by being used appropriately.
</p>]]></description>
      <pubDate>Wed, 18 May 2011 10:18:21 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPBuilder.com: Using the Factory Pattern in PHP Applications]]></title>
      <guid>http://www.phpdeveloper.org/news/15963</guid>
      <link>http://www.phpdeveloper.org/news/15963</link>
      <description><![CDATA[<p>
On PHPBuilder.com today, there's a new tutorial posted about using one of the more well-known design patterns in your PHP applications - <a href="http://www.phpbuilder.com/columns//factory-pattern/Octavia_Anghel022311.php3">the Factory Pattern</a>. Design patterns are <a href="http://en.wikipedia.org/wiki/Design_pattern">repeatable methods</a> for doing common tasks in a "best practices" sort of way.
</p>
<blockquote>
In this article you will learn how to use the factory pattern design in your PHP application to construct different objects for interrogating a database (books) and displaying the records from a table (bookstore) [...] The essence of the factory method pattern is to "define an interface for creating an object, but let the subclasses decide which class to instantiate. The Factory method lets a class defer instantiation to subclasses."
</blockquote>
<p>
He illustrates with a few sample scripts - one that displays a series of messages on factoried instances of a class, another that randomizes a display of images and another that handles book data and outputs the results.
</p>]]></description>
      <pubDate>Fri, 25 Feb 2011 10:07:37 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Label Media Blog: Design Patterns in PHP - Factory method]]></title>
      <guid>http://www.phpdeveloper.org/news/15501</guid>
      <link>http://www.phpdeveloper.org/news/15501</link>
      <description><![CDATA[<p>
On the Label Media blog today there's a new post from <i>Tom Rawcliffe</i> (the first part of a series) about a common design pattern you can use in your applications - <a href="http://www.labelmedia.co.uk/blog/posts/design-patterns-factory-method.html">the factory pattern</a>.
</p>
<blockquote>
A design pattern is a template used by software engineers as a guideline of how to solve a particular problem. [...] In this series of articles I plan to explore some of the design patterns that i have found most useful in my time as a PHP developer, providing examples and notes. So, this being the first, we'll take a look at the Factory Method Pattern.
</blockquote>
<p>
He defines the pattern - an interface to a class without the caller having to know what type of class it is - and a code example showing an abstract class with a "Factory" method that pulls information from either a jpeg or png class based on the extension of the file name given.
</p>]]></description>
      <pubDate>Fri, 26 Nov 2010 13:56:03 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[NETTUTS.com: A Beginner's Guide to Design Patterns ]]></title>
      <guid>http://www.phpdeveloper.org/news/14761</guid>
      <link>http://www.phpdeveloper.org/news/14761</link>
      <description><![CDATA[<p>
On NETTUTS.com today there's <a href="http://net.tutsplus.com/articles/general/a-beginners-guide-to-design-patterns">a new tutorial</a> that introduces a bit more advanced concept in the development process - design patterns.
</p>
<blockquote>
Design patterns are optimized, reusable solutions to the programming problems that we encounter every day. A design pattern is not a class or a library that we can simply plug into our system; it's much more than that. It is a template that has to be implemented in the correct situation. It's not language-specific either. A good design pattern should be implementable in most - if not all - languages, depending on the capabilities of the language. 
</blockquote>
<p>
They introduce a few of the more widely used patterns including the strategy pattern, adapter pattern, factory methods, decorator and singleton patterns. Each comes with a bit of code showing how it would work and a "where would I use this?" section with a better example.
</p>]]></description>
      <pubDate>Thu, 08 Jul 2010 08:47:55 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Gonzalo Ayuso's Blog: Moving singleton and factory patterns to Abstract with php 5.3]]></title>
      <guid>http://www.phpdeveloper.org/news/13922</guid>
      <link>http://www.phpdeveloper.org/news/13922</link>
      <description><![CDATA[<p>
<i>Gonzalo Ayuso</i> <a href="http://gonzalo123.wordpress.com/2009/12/07/moving-singleton-and-factory-patterns-to-abstract-with-php-5-3/">came across a situation</a> where he needed to create a factory method inside of multiple classes but didn't want to have to create them each time. With class inheritance there had to be another way.
</p>
<blockquote>
I have built a backend library. I have a tree of classes and i want to use singleton and factory patterns to my class set. Easy isn't it? [...] Now imagine you have a lot of classes. You must create over and over the factory function in every classes. 
</blockquote>
<p>
An abstract class is a perfect fit for this sort of thing, but there's not a good way to return the correct kind of object back from the factory method. That is, until you do some magic with a PHP installation version 5.3 and higher. With the <a href="http://php.net/manual/en/function.get-called-class.php">get_called_class</a> function, you can easily figure out where the request came from and return a correct object instance with one line.
</p>]]></description>
      <pubDate>Wed, 27 Jan 2010 13:55:12 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Giorgio Sironi's Blog: Practical PHP Patterns]]></title>
      <guid>http://www.phpdeveloper.org/news/13814</guid>
      <link>http://www.phpdeveloper.org/news/13814</link>
      <description><![CDATA[<p>
Starting off a new series on his blog <i>Giorgio Sironi</i> has posted <a href="http://giorgiosironi.blogspot.com/2010/01/practical-php-patterns-abstract-factory.html">two</a> <a href="http://giorgiosironi.blogspot.com/2010/01/practical-php-patterns-builder.html">new</a> tutorials</a> looking at PHP design patterns - specifically the Abstract Factory and Builder patterns.
</p>
<blockquote>
[This series will] touch the majority of the known design patterns, with a special look at their application in a php context. A running code sample will be provided for each part of this series, along with the theory and the terminology of each pattern.
</blockquote>
<p>
In the <a href="http://giorgiosironi.blogspot.com/2010/01/practical-php-patterns-abstract-factory.html">Abstract Factory</a> (or just Factory) post he includes a <a href="http://yuml.me/diagram/scruffy/class/%5BClient%5D-%3E%5BAbstractFactory%5D,%20%5BClient%5Duses-.-%3E%5BAbstractProduct%5D,%20%5BAbstractFactory%5Dcreates-.-%3E%5BAbstractProduct%5D,%20%5BConcreteFactory%5Dcreates-.-%3E%5BConcreteProduct%5D,%20%5BAbstractFactory%5D%5E-%5BConcreteFactory%5D,%20%5BAbstractProduct%5D%5E-%5BConcreteProduct%5D">diagram</a> of the pattern's relationship with other "participants" and has a Zend Framework-based code sample to create a simple WidgetHelper. In the <a href="http://giorgiosironi.blogspot.com/2010/01/practical-php-patterns-builder.html">second article</a> he looks at the Builder pattern and how it can make creating instances of complex objects a bit easier. As before a <a href="http://yuml.me/diagram/scruffy/class/%5BDirector%5D-%3E%5BBuilder%5D,%20%5BBuilder%5D%5E-%5BConcreteBuilder%5D,%20%5BConcreteBuilder%5Dcreates-.-%3E%5BProduct%5D">diagram</a> and code are included.
</p>
<p>
You can keep up with the rest of the posts in the series as they're added by following along <a href="http://giorgiosironi.blogspot.com/search/label/practical%20php%20patterns">here</a>.
</p>]]></description>
      <pubDate>Mon, 11 Jan 2010 11:11:48 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Giorgio Sironi's Blog: When to inject: the distinction between newables and injectables]]></title>
      <guid>http://www.phpdeveloper.org/news/12974</guid>
      <link>http://www.phpdeveloper.org/news/12974</link>
      <description><![CDATA[<p>
Following up on a <a href="http://www.phpdeveloper.org/news/12960">previous post</a> about dependency injection, <i>Giorgio Sironi</i> has posted <a href="http://giorgiosironi.blogspot.com/2009/07/when-to-inject-distinction-between.html">this new look</a> at when to use dependency injection and when its still better to handle objects individually.
</p>
<blockquote>
In the last post, I introduced Dependency Injection and show useful cases where it allows classes decouplng. I also wrote about the problem of how to inject a service in a class that has to be instantiated not application wide but in the business logic.
</blockquote>
<p>
He creates an example that shows a not-so-good place to use dependency injection and offers a solution - a factory that creates the objects as they're needed instead of having them floating around when they're not needed. He also talks about the difference between two types of business objects to consider in dependency injection: entities and services (hint: one depends on the other).
</p>]]></description>
      <pubDate>Fri, 31 Jul 2009 10:58:39 -0500</pubDate>
    </item>
  </channel>
</rss>

