News Feed
Jobs Feed
Sections




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

DevShed:
Violating the Liskov Substitution Principle - PHP
June 30, 2011 @ 08:36:31

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.

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.

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 problem comes up when he tries to work with his objects and a partial view instead of a composite view is passed in.

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.

0 comments voice your opinion now!
liskov substitution principle tutorial view render exception


blog comments powered by Disqus

Similar Posts

PHPBuilder.com: Installing Apache and PHP under Win32

Graham Bird's Blog: Extra-pretty URLs with slugs

IBM developerWorks: Intro to MVC Programming with Agavi, Part 1: Open a whole new world with Agavi

Ariz Jacinto's Blog: Compiling PHP with MSSQL Server's Native ODBC Driver for Linux as a PDO Driver

Rob Allen's Blog: Zend Framework Tutorials (an Update and Zend_Auth)


Community Events











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


security release hhvm facebook opinion application composer language package code overview example hack podcast framework install symfony2 unittest introduction component

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