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 Open/Closed Principle
November 08, 2012 @ 10:09:32

On PHPMaster.com there's a new post continuing their look at the SOLID development methodologies with the "O" in the acronym - the Open/Closed Principle:

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.

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.

0 comments voice your opinion now!
solid design principle openclosed tutorial


blog comments powered by Disqus

Similar Posts

ProDevTips.com: Ajax, ZF and Smarty feed reader (Part 2)

PHP-GTK Community Site: an IMAP Client & Screenshots with Gdk

Fortrabbit.com: Video: Symfony2 on fortrabbit

RoofTopSolutions.nl: Caching in PHP using the filesystem, APC, and Memecached

Decal CMS Blog: Testing your website before launching: how to let content drive design (Part 1)


Community Events

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


voicesoftheelephpant podcast introduction xdebug opinion example framework community unittest release laravel install interview laravel5 library php7 language extension api series

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