News Feed
Sections




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

QaFoo.com:
Code Reuse By Inheritance
January 20, 2014 @ 10:55:18

On the Qafoo blog today Kore Nordmann has a new post talking about code reuse through inheritance. He talks about base classes, sharing code and abstraction.

To me, inheritance has two properties: Defining an is-a relationship [and] making it possible to share code between classes by extending from a common base class. The is-a relationship between classes is one thing I like to use inheritance for. [...] The other thing you can use inheritance for is to share code between multiple classes. [...] I personally think that the latter is one of the worst things you can do in object oriented design. Bear with me for a moment and let me try to explain why I think that.

His example of doing it the wrong way is using the Active Record design pattern and how it's usually implemented - storage logic in the base class and business/table logic in the extending class. He then gets into an example that's a bit "smaller" creating diff display functionality and how the "code reuse by inheritance" creeps in a lot in helper methods. He also briefly looks at testing (or not testing) private methods and and the "Depth of Inheritance Tree" metric's recommended value.

0 comments voice your opinion now!
code reuse inheritance helper activerecord testing depth

Link: http://qafoo.com/blog/063_code_reuse_by_inheritance.html

blog comments powered by Disqus

Similar Posts

Travis Swicegood's Blog: Why Inheritance Sucks

Zend Developer Zone: Improving Code Quality with Flash Builder 4 and PHPUnit

Chris Hartjes: You Need tests...just Not Yet

Simon Holywell: Idiorm and Paris 1.3.0 released - the minimalist ORM and fluent query builder for PH

CatsWhoCode.com: 8 useful code snippets to get started with WordPress 3.0


Community Events





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


list threedevsandamaybe podcast api laravel release language tips conference zendserver interview introduction symfony deployment community framework series developer development code

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