<?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>Mon, 20 May 2013 02:48:02 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Benjamin Eberlei: Doctrine and SOLID]]></title>
      <guid>http://www.phpdeveloper.org/news/19137</guid>
      <link>http://www.phpdeveloper.org/news/19137</link>
      <description><![CDATA[<p>
<i>Benjamin Eberlei</i> has a new post to his site today answering a question he sometimes gets about <a href="http://www.whitewashing.de/2013/02/04/doctrine_and_solid.html">using Doctrine2 in a SOLID context</a> (more on SOLID development <a href="http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)">here</a>) as it seems difficult to follow the Single Responsibility Principle with how the tool is used.
</p>
<blockquote>
These problems are related to the inability to share behavioral code through aggregation and the complexity of state transformations. Combining both, your average entity with 5-15 fields can end up with hundrets or thousands lines of code. The solutions to both problems boil down to <a href="http://www.jbrains.ca/permalink/the-four-elements-of-simple-design">minimizing duplication and maximizing clarity</a>.
</blockquote>
<p>
He looks at two different kinds of objects Doctrine uses in its setup, the value objects and method objects, and "maximize clarity" on them by dividing them up into more functional-related objects, passed into each other via method injection.
</p>]]></description>
      <pubDate>Tue, 05 Feb 2013 11:09:33 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[NetTuts.com: How to Write Code That Embraces Change]]></title>
      <guid>http://www.phpdeveloper.org/news/19132</guid>
      <link>http://www.phpdeveloper.org/news/19132</link>
      <description><![CDATA[<p>
On NetTuts.com today there's a great new article about how to <a href="http://net.tutsplus.com/tutorials/how-to-write-code-that-embraces-change/">write code that embraces change</a> and can be easily updated and reconfigured due to a decoupled nature and use of good OOP concepts.
</p>
<blockquote>
Writing code, which is easy to change is the Holy Grail of programming. Welcome to programming nirvana! But things are much more difficult in reality: source code is difficult to understand, dependencies point in countless directions, coupling is annoying, and you soon feel the heat of programming hell. In this tutorial, we will discuss a few principles, techniques and ideas that will help you write code that is easy to change.
</blockquote>
<p>
He covers some of the good OOP principles to think about when developing - like cohesion, orthogonality and coupling (via class methods, polymorphism, dependency injection or interfaces). He spends some time looking at the <a href="http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)">SOLID</a> development principles and how you can implement each of them in some sample code. He also talks some about high level design and how the separation of concerns can help make your code easier to maintain and change.
</p>]]></description>
      <pubDate>Mon, 04 Feb 2013 13:18:58 -0600</pubDate>
    </item>
    <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: 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[Freek Lijten's Blog: SOLID - The S is for Single responsibility]]></title>
      <guid>http://www.phpdeveloper.org/news/17723</guid>
      <link>http://www.phpdeveloper.org/news/17723</link>
      <description><![CDATA[<p>
<i>Freek Lijten</i> has <a href="http://www.freeklijten.nl/home/2012/03/23/SOLID-The-S-is-for-Single-responsibility">written up a new post</a> to his blog about a set of development principles that have been getting more press in the PHP community lately - <a href="http://en.wikipedia.org/wiki/SOLID">SOLID</a>. In his post he starts with a look at the "S" in the set - "Single Responsibility".
</p>
<blockquote>
The single responsibility principle isn't all that hard to explain. It states that an object should do one thing, and one thing only. [...]  A responsibility is a reason to change, and a class should only have one of those. Now all of this may sound abstract and since the objective of this series is to avoid just that we'll just dive into the why now.
</blockquote>
<p>
He includes some sample code to illustrate, going with an active record implementation, some of the problems that come with a typical setup including issues with unit testing, bad practice of using the data store directly, etc. He shows a refactored code example that splits out the functionality previously all in the one class ("Bike") into three different ones - one is the normal Bike object, another compares the Bikes and the third works with the data store to handle the <a href="http://en.wikipedia.org/wiki/Create,_read,_update_and_delete">CRUD</a> for the objects.
</p>]]></description>
      <pubDate>Fri, 23 Mar 2012 11:23:59 -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>
  </channel>
</rss>
