<?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>Fri, 24 May 2013 11:53:55 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Freek Lijten: SOLID - The D is for Dependency Inversion Principle]]></title>
      <guid>http://www.phpdeveloper.org/news/18980</guid>
      <link>http://www.phpdeveloper.org/news/18980</link>
      <description><![CDATA[<p>
<i>Freek Lijten</i> has posted the <a href="http://www.freeklijten.nl/home/2013/01/02/SOLID-The-D-is-for-Dependency-Inversion-Principle">last article in his series</a> looking at the <a href="http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)">SOLID</a> development principles, this time looking at "D", the Dependency Inversion Principle.
</p>
<blockquote>
The DIP deals with avoiding mixing different levels of abstraction in your code. In this article we will explore the last of these principles in depth. [...] I want to show you how depending on abstractions makes our lives easier in a larger example. Since we're going to be loading, updating and storing bikes a lot in our application I would like an Api for that. It would not be such a good idea to write the same queries or perform the same validation over and over.
</blockquote>
<p>
He includes two examples - one a bit simplistic involving bike storage and another more complex that uses interfaces to define structure and object injection rather than passing data around. He also tries to help clear up some of the confusion that might happen around dependency inversion and dependency injection.
</p>]]></description>
      <pubDate>Wed, 02 Jan 2013 10:25:46 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPMaster.com: Inversion of Control - The Hollywood Principle]]></title>
      <guid>http://www.phpdeveloper.org/news/18865</guid>
      <link>http://www.phpdeveloper.org/news/18865</link>
      <description><![CDATA[<p>
In <a href="http://phpmaster.com/inversion-of-control-the-hollywood-principle/">this new tutorial</a> on PHPMaster.com, <i>Alejandro Gervasio</i> looks at the Inversion of Control methodology and how it's more than just an abstract reference to dependency injection.
</p>
<blockquote>
Traditionally, application components have been designed to operate on and control the execution environment, an approach that delivers well to some extent. [...]  Instead of making the module completely responsible for logging data to multiple endpoints, we can transfer the responsibility straight to the external environment. [...] Not surprisingly, the process of inverting these responsibilities between components and the environment is formally known as Inversion of Control (or in a more relaxed jargon, <a href="http://en.wikipedia.org/wiki/Hollywood_principle">The Hollywood Principle</a>), and its implementation can be a real boost when it comes to developing extensible, highly-decoupled program modules.
</blockquote>
<p>
He uses a set of domain objects (Posts and Comments in a typical blog structure) and the Observer pattern to show how mixed up things might get if the application isn't carefully coded. He takes this and updates it to include a "comment notification service" that implements the SplObserver and is attached to the post to be executed on an event (in this case, the setting of a new comment).
</p>]]></description>
      <pubDate>Mon, 10 Dec 2012 09:43:50 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPMaster.com: The Single Responsibility Principle]]></title>
      <guid>http://www.phpdeveloper.org/news/18789</guid>
      <link>http://www.phpdeveloper.org/news/18789</link>
      <description><![CDATA[<p>
On PHPMaster.com today <i>Alejandro Gervasio</i> has a new tutorial posted about the <a href="http://phpmaster.com/the-single-responsibility-principle/">Single Responsibility Principle</a> - a guideline that states that each class should only have one "area of concern" and not try to do to much.
</p>
<blockquote>
One of the most notorious consequences of this rational associative process is that, at some point, we effectively end up creating classes that do too much. The so-called "God class" is quite possibly the most extreme and coarse example of a structure that packages literally piles of unrelated operations behind the fence of the same API, but there are other subtle, more furtive situations where assigning of multiple roles to the same class are harder to track down. [...] What the principle attempts to promote is that classes must always be designed to expose only one area of concern and the set of operations they define and implement must be aimed at fulfilling that concern in particular and nothing else.
</blockquote>
<p>
He starts off with a typical violation of the principle, showing a class that not only handles user data but also includes the functions to work with the database directly as well (insert/update/delete). He refactors this into a few much more manageable classes - a mapping class to handle the database interaction and a "User" class representative of a true user object. 
</p>]]></description>
      <pubDate>Thu, 22 Nov 2012 11:58:06 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPMaster.com: The Open/Closed Principle]]></title>
      <guid>http://www.phpdeveloper.org/news/18716</guid>
      <link>http://www.phpdeveloper.org/news/18716</link>
      <description><![CDATA[<p>
On PHPMaster.com there's a new post continuing their look at the SOLID development methodologies with the "O" in the acronym - the <a href="http://phpmaster.com/the-open-closed-principle/">Open/Closed Principle</a>:
</p>
<blockquote>
I have to admit the first time I peeked at the academic definition of the Open/Closed Principle, its predicate was surprisingly clear to me. Leaving all of the technical jargon out of the picture, of course, its dictate was pretty much the mantra that we've heard so many times before: "Don't hack the core". Well, admittedly there's a pinch of ambiguity since there are at least two common approaches to keeping the "core" neatly preserved while extending its functionality. The first one (and why I used deliberately the term "extending") would be appealing to Inheritance. [...] The second approach is Composition. 
</blockquote>
<p>
He illustrates the effective application of the principle with the creation of a HTML rendering class. The first version is non-polymorphic and just renders the example DIV and P elements that are passed into it. He changes this up by shifting these element classes into something extending an AbstractHtmlElement class (sharing an interface between them) and updating the renderer to handle these correctly.
</p>]]></description>
      <pubDate>Thu, 08 Nov 2012 10:09:32 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPMaster.com: Constructors and the Myth of Breaking the Liskov Substitution Principle]]></title>
      <guid>http://www.phpdeveloper.org/news/18569</guid>
      <link>http://www.phpdeveloper.org/news/18569</link>
      <description><![CDATA[<p>
On PHPMaster.com there's a new post in a series looking at the <a href="http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)">SOLID</a> design principles in PHP development. In <a href="http://phpmaster.com/constructors-and-the-myth-of-breaking-the-lsp/">this new tutorial</a> they try to dispel the myth that constructors break the Liskov Substitution Principle ("L" in "SOLID").
</p>
<blockquote>
Rants aside, the morale of the story can be boiled down to the following: "Object construction is not part of the contract honored by its implementers". It's easier to grasp concepts by example rather than reading dull theory, so in this article I'll be demonstrating from a practical standpoint how the implementation of different constructors down the same hierarchy isn't a violation of the <a href="http://phpmaster.com/liskov-substitution-principle/">Liskov Substitution Principle</a>, which is a reason why you shouldn't fall into the temptation of tainting your interfaces with constructors.
</blockquote>
<p>
He illustrates the point with a simple PDO class that implements a "DatabaseAdapterInterface" interface that defines its own constructor that follows the <a href="http://us3.php.net/manual/en/pdo.construct.php">defaults</a> of the PDO extension. He goes on and changes the constructor for the class a bit to take in an array of config options rather than the DSN/User/Password combo. Inside of this constructor, those values are then taken and pushed into PDO to create the connection. He also suggests one other solution - the injection of a connection object ("ConnectionDefinition") into the constructor instead of the configuration directly.
</p>]]></description>
      <pubDate>Mon, 08 Oct 2012 11:53:13 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Freek Lijten: SOLID - The L is for Liskov Substitution Principle]]></title>
      <guid>http://www.phpdeveloper.org/news/18438</guid>
      <link>http://www.phpdeveloper.org/news/18438</link>
      <description><![CDATA[<p>
In <a href="http://www.freeklijten.nl/home/2012/09/04/SOLID-The-L-is-for-Liskov-Substitution-Principle">this new post</a> to his site <i>Freek Lijten</i> picks back up his series on the SOLID design principles with a look at the "L" in the acronym - the Liskov Substitution Principle.
</p>
<blockquote>
The Liskov Substitution Principle (LSP) was coined by Barbara Liskov as early as 1987. The principle is very tightly connected to the earlier discussed Open Closed Principle. A good way of adhering to the OCP is understanding and implementing code that uses the Liskov Substitution Principle. In this article we will discover why and how.
</blockquote>
<p>
He gives a more understandable explanation of what the rule tries to suggest - a standardized <a href="http://php.net/interface">interface</a> that each of his "Bike" instances follows to ensure the contract of a consistent API. Then each of the child classes can reliably assume that there are methods they can use because they'll always inherit them.
</p>]]></description>
      <pubDate>Tue, 04 Sep 2012 08:37:46 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPMaster.com: The Dependency Inversion Principle]]></title>
      <guid>http://www.phpdeveloper.org/news/17938</guid>
      <link>http://www.phpdeveloper.org/news/17938</link>
      <description><![CDATA[<p>
Continuing on in their series looking at the <a href="http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)">SOLID</a> development principles, <i>Alejandro Gervasio </i> picks back up and looks at the "D" in the set - the <a href="http://phpmaster.com/dip-intro/">dependency inversion principle</a>.
</p>
<blockquote>
While some central concepts in the realm of object-oriented design are generally harder to digest at first, such as separation of concerns and implementation switching, more intuitive and untangled paradigms on the other hand are simpler, like programming to interfaces. Unfortunately, the DIP's formal definition is surrounded by a double-edged curse/blessing that often makes programmers gloss over it, as in many cases there's an implicit assumption that the principle is nothing but a fancy expression for the aforementioned "programming to interfaces" commandment.
</blockquote>
<p>
He talks about how decoupling your code and working against interfaces is only part of the equation. The other half is the actual "inversion" part of the process - the ownership that the high-level modules must have over the abstractions. He illustrates with an example, a storage module that is highly dependent on a Serializer. Using the DIP principle, he turns this around and refactors his storage class to take in an Encoder object as a part of its construction. Complete source for both versions is included.
</p>]]></description>
      <pubDate>Thu, 10 May 2012 08:52:19 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Freek Lijten's Blog: SOLID - The O is for Open Closed Principle]]></title>
      <guid>http://www.phpdeveloper.org/news/17916</guid>
      <link>http://www.phpdeveloper.org/news/17916</link>
      <description><![CDATA[<p>
<i>Freek Lijten</i> has posted the <a href="http://www.freeklijten.nl/home/2012/05/07/SOLID-the-O-is-for-Open-Closed-Principle">second part</a> of his series looking at the <a href="http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)">SOLID</a> development methodology. In this latest post his looks at the second letter in the acronym - "O" for "Open Closed Principle."
</p>
<blockquote>
Software that requires an enormous amount of changes to implement one new feature or fix a bug is unstable and should be considered as "bad". Software should be designed so, that in case of a new feature, no existing classes should have to change. In other words: it is closed for modification. Existing software may be extended to achieve new features however.
</blockquote>
<p>
He starts off with a "What" section explaining a bit more about what this open/closed means for your code and gets into an example showing it in a more practical way. He shows how to take the principle and refactor an API connector class to pass in the object it needs (Bike) and use that to get information (rather than just passing in the data). He uses a <a href="http://en.wikipedia.org/wiki/Factory_pattern">Factory</a> to get the object type he needs based on the Bike type.
</p>]]></description>
      <pubDate>Mon, 07 May 2012 10:45:37 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPMaster.com: The Liskov Substitution Principle]]></title>
      <guid>http://www.phpdeveloper.org/news/17442</guid>
      <link>http://www.phpdeveloper.org/news/17442</link>
      <description><![CDATA[<p>
On PHPMaster.com today there's a new post from <i>Alejandro Gervasio</i> about a part of the <a href="http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)">SOLID</a> development methods - the <a href="http://phpmaster.com/liskov-substitution-principle/">Liskov Substitution Principle</a> - the idea that objects should be replaceable with instances of their subtypes without a change to the architecture of the application.
</p>
<blockquote>
Even when the formal definition of the LSP makes eyes roll back (including mine), at its core it boils down to avoiding brittlely-defined class hierarchies where the descendants expose a behavior radically different from the base abstractions consuming the same contract.
</blockquote>
<p>
He includes an example with a "deleted scene" from the Matrix depicting an attempted override of the PDO functionality with a subclass that, unfortunately, does not match the original's structure/method definitions. The problem was in the difference between the method signature for the "query" method. It help resolve situations like this he recommends creating a "contract" in the form of an interface your code can implement, forcing it to conform to a certain structure. Using this, he provides a rewrite of the "PdoAdapter" class to match the original signature 
</p>]]></description>
      <pubDate>Tue, 24 Jan 2012 13:40:35 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Josh Adell's Blog: Command Invoker Pattern with the Open/Closed Principle]]></title>
      <guid>http://www.phpdeveloper.org/news/17398</guid>
      <link>http://www.phpdeveloper.org/news/17398</link>
      <description><![CDATA[<p>
In a response to a <a href="http://phpdeveloper.org/news/17389">recent post</a> on DZone.com about the "Open/Closed Principle" <i>Josh Adell</i> has <a href="http://blog.everymansoftware.com/2012/01/command-invoker-pattern-with-openclosed.html">posted an example</a> of a " flexible and extendable command invocation solution" implementing this <a href="http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)">SOLID</a> idea.
</p>
<blockquote>
Let's overcome some of these issues [with only being able to extend the invoker class and that the invoker needs to know how to create commands], and also make the code even more extensible. I'll use a simplified command invoker to demonstrate.
</blockquote>
<p>
His code is included - the creation of a "Command" interface and two comments that implement it: "HelloCommand" and "PwdCommand", each with "register" and "execute" methods. His "Invoker" class then only needs to be told how to map these commands and the "register" is called as they're needed. You can find the full example code for this invocation example <a href="http://gist.github.com/1610148">in this gist</a>.
</p>]]></description>
      <pubDate>Mon, 16 Jan 2012 10:04:42 -0600</pubDate>
    </item>
  </channel>
</rss>
