News Feed
Sections




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

Freek Lijten's Blog:
SOLID - The S is for Single responsibility
March 23, 2012 @ 11:23:59

Freek Lijten has written up a new post to his blog about a set of development principles that have been getting more press in the PHP community lately - SOLID. In his post he starts with a look at the "S" in the set - "Single Responsibility".

The single responsibility principle isn't all that hard to explain. It states that an object should do one thing, and one thing only. [...] A responsibility is a reason to change, and a class should only have one of those. Now all of this may sound abstract and since the objective of this series is to avoid just that we'll just dive into the why now.

He includes some sample code to illustrate, going with an active record implementation, some of the problems that come with a typical setup including issues with unit testing, bad practice of using the data store directly, etc. He shows a refactored code example that splits out the functionality previously all in the one class ("Bike") into three different ones - one is the normal Bike object, another compares the Bikes and the third works with the data store to handle the CRUD for the objects.

0 comments voice your opinion now!
solid development principles single responsibility


blog comments powered by Disqus

Similar Posts

Sara Goleman's Blog: A yodeler falls silent. (Andrei Zmievski's Move from Yahoo)

Rafael Dohms' Blog: PHP Development in the Cloud by Ivo Jansch and Vito Chin

Phil Sturgeon: Build API's That You Wont Hate: Part 1 - Useful Database Seeding

MakeUseOf: Create The Perfect PHP Development Environment In Android

NetTuts.com: How to Write Code That Embraces Change


Community Events





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


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

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