News Feed
Sections




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

PHPMaster.com:
The Liskov Substitution Principle
January 24, 2012 @ 13:40:35

On PHPMaster.com today there's a new post from Alejandro Gervasio about a part of the SOLID development methods - the Liskov Substitution Principle - the idea that objects should be replaceable with instances of their subtypes without a change to the architecture of the application.

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.

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

0 comments voice your opinion now!
liskov substitution principle tutorial example solid development pdo interface


blog comments powered by Disqus

Similar Posts

PHPBuilder.com: Getting started with Flex and Zend_Amf

Jani Hartikainen's Blog: Sending files better: Apache mod_xsendfile and PHP

Kevin Schroeder's Blog: Connecting to the Zend Developer Cloud with PDT

Dean Clatworthy: Theming/styling error messages in Symfony 2

OpenSky Blog: Inheritance in PHP, or why you want to use an Interface or an Abstract class...


Community Events





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


library list bugfix api series introduction laravel framework package release interview tips community opinion deployment symfony voicesoftheelephpant podcast install language

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