News Feed
Sections




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

Bence Eros' Blog:
Using Inheritance
December 02, 2010 @ 12:14:39

In this new post to his blog, Bence looks at how inheritance is commonly used in PHP applications and how, if not controlled carefully can be something that creates bad habits among PHP developers.

In fact I think that using inheritance all the time is a very big mistake and makes your code hard to maintain and more hard to integrate (the latter is a mistake for application codes and a fatal mistake for libraries). The main problem with inheritance is that if you use it for coupling two classes, then a very important property of the subclass is used up: it's superclass. It is taken, reserved, and it can not be used for anything else furthermore. If you want to connect your subclass to an other class using inheritance, you can't.

He recommends avoiding the typical uses of typical superclass/subclass inheritance unless what you're doing specifically requires it. Working with interfaces, abstract classes and good composition planning is a much better idea.

1 comment voice your opinion now!
abstract class inheritance opinion composition


blog comments powered by Disqus

Similar Posts

Hasin Hayder's Blog: Getting comfy with PhpStorm - one of the best IDEs so far!

KillerPHP Blog: PHP Interfaces: when and why you should use them instead of classes?

Strattonbrazil's Blog: php to python: Why PHP is now dead to me

Clay Loveless' Blog: 5 Reasons Simple Cloud is a Dark Cloud

Gonzalo Ayuso's Blog: First impressions about namespaces in PHP


Community Events





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


opinion release series language community framework threedevsandamaybe interview unittest list configure podcast install refactor laravel developer testing wordpress code introduction

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