News Feed

News Archive
feed this:

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

Mathias Verraes:
Final Classes
May 13, 2014 @ 09:48:43

Mathias Verraes has posted some of his thoughts about using "final" in classes and what kind of impression it gives about your code.

I make all my classes final by default. I even configured the templates in my IDE prefix new classes with 'final'. I've often explained my reasoning to people. A blog post is in order! A guiding principle here is Clarity of Intent. [...] The reason we need clean code, is not for the compiler. It's to help our fellow developers, third parties, and even ourselves in six months time, understand the purpose and the design of our system.

He relates this concept of clean code and clarity back to the SOLID development principles, specifically the "Open/Closed Principle". This principle states that software should be open for extension but not for modification. It suggests that providing a stable, known API is a responsibility of the developer and using things like callbacks and listeners is a better way to extend. He gets into a bit more PHP-specific issues around using "final", including the difficulties that it can cause during testing.

0 comments voice your opinion now!
final class inheritance extension solid openclosed principle

The Open/Closed Principle
November 08, 2012 @ 10:09:32

On 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

Community Events

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

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

All content copyright, 2014 :: - Powered by the Solar PHP Framework