<?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, 22 May 2013 11:06:04 -0500</pubDate>
    <ttl>30</ttl>
    <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 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[DevShed: PHP Object Oriented Programming using LSP]]></title>
      <guid>http://www.phpdeveloper.org/news/16589</guid>
      <link>http://www.phpdeveloper.org/news/16589</link>
      <description><![CDATA[<p>
In another part of their series looking at the <a href="http://en.wikipedia.org/wiki/Solid_(object-oriented_design)">SOLID</a> principles of software development, DevShed focuses again on <a href="http://www.devshed.com/c/a/PHP/PHP-Object-Oriented-Programming-using-LSP/">using LSP</a> (the Liskov Substitution Principle) to help you organize your application (part one is <a href="http://www.devshed.com/c/a/PHP/PHP-Liskov-Substitution-Principle/">here</a>).
</p>
<blockquote>
Even though its formal definition is somewhat hard to grasp, in practical terms it states that methods defined in a base class (or interface) and their derivatives must have the same signature, preconditions should be weakened in the formers, and post-conditions should be strengthened. In addition, if methods in subtypes throw exceptions, they should be of the same type as the ones thrown by the parent abstraction.
</blockquote>
<p>
You'll need to <a href="http://www.devshed.com/c/a/PHP/PHP-Liskov-Substitution-Principle/">read the previous tutorial</a> for things to make sense here. They take off running from there, though and get straight into refactoring the previous example to correct a violation of LSP. In the end you'll have a layout/view system that correctly follows the principles and is pretty simple to use too.
</p>]]></description>
      <pubDate>Thu, 14 Jul 2011 08:57:17 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[DevShed: Violating the Liskov Substitution Principle - PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/16537</guid>
      <link>http://www.phpdeveloper.org/news/16537</link>
      <description><![CDATA[<p>
On DevShed today there's a new tutorial posted talking about the Liskov Substitution Principle (part of the SOLID set of principles) and how to use it in a practical example using some object-oriented PHP.
</p>
<blockquote>
However, not all is bad with Inheritance. When used properly it can be a great ally. The question that comes to mind is: how can you keep away from building derivatives that behave totally different from the chosen abstraction(s)? Here's exactly where the Liskov Substitution Principle (LSP) comes into play.
</blockquote>
<p>
They choose to illustrate the principle in the form of a view renderer that, when an unintentional issue happens, throws a new exception. He creates the abstract class to generate the view objects and creates a few child objects that extend it. using these, he creates a set of templates that render a header/footer/body with the data given. The <a href="http://www.devshed.com/c/a/PHP/PHP-Liskov-Substitution-Principle/2/">problem comes up</a> when he tries to work with his objects and a partial view instead of a composite view is passed in. 
</p>
<p>
It's a complicated situation to follow, but it does help make the principle a bit more clear. I'd suggest following it all the way through and possibly even trying out their code (included) to make it even more clear.
</p>]]></description>
      <pubDate>Thu, 30 Jun 2011 08:36:31 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Zend Developer Zone: Liskov Substitution Principle...attempted]]></title>
      <guid>http://www.phpdeveloper.org/news/16436</guid>
      <link>http://www.phpdeveloper.org/news/16436</link>
      <description><![CDATA[<p>
In <a href="http://phpdeveloper.org/news/16431">a previous post</a> to the Zend Developer Zone <i>Keith Casey</i> talked about the <a href="http://en.wikipedia.org/wiki/Solid_(object-oriented_design)">SOLID</a> principles of software development, a set of guidelines that can help to make software more maintainable and easier to work with. In <a href="http://devzone.zend.com/article/15273-Liskov-Substitution-Principle..-attempted">this new post</a> he looks at the "L" in SOLID, the Liskov Substitution Principle.
</p>
<blockquote>
So the Liskov Substitution Principle boils down to: method/class preconditions cannot be strengthened, method/class post conditions can't be weakened, all exceptions thrown must equally interchangeable and
method signatures should be completely compatible.
</blockquote>
<p>
To help make this all a bit clearer, he includes some code showing a basic class (Rectangle) and how difficult it can be to try to appease all of the principles above without the "fix one, break another" scenario. On comment to the post suggests something that might help things a bit - <a href="http://stackoverflow.com/questions/4019748/programming-by-contracts-in-php">programming by contract</a>.
</p>]]></description>
      <pubDate>Tue, 07 Jun 2011 11:09:41 -0500</pubDate>
    </item>
  </channel>
</rss>
