News Feed
Sections




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

PHPBuilder.com:
PHP Dependency Injection Creates More Maintainable Code
May 02, 2011 @ 09:52:05

On PHPBuilder.com Jason Gilmore has posted a new article looking at the benefits of dependency injection in helping you keep your code more maintainable and well-structured.

Of course, the advantages of object-orientation can only be fully exploited when implemented in conjunction with best practices such as encapsulation and inheritance. One such "implementational" best practice is dependency injection, a design pattern that facilitates the decoupling of otherwise dependent components. [...] Save yourself the trouble and decouple components using dependency injection.

He gives an example of how a simple dependency injection (DI) method on an "Account" class to take the database connection dependency out of the actual class and into an encapsulated object. This way, any sort of standardized database object can be passed in and acted upon. He also mentions two dependency injection containers you could use to help you implement it - Symfony's and Pimple.

0 comments voice your opinion now!
maintainable code dependency injection tutorial


blog comments powered by Disqus

Similar Posts

John Maver's Blog: How to create a Bebo application using PHP 5

Greg Beaver's Blog: Be careful of PEAR 1.4.4 and older installs when uninstalling a package

Ade Slade's Blog: Integrating Zend Framework 1 and Pimple

PHPBuilder.com: Using XML, Part 5 - SOAP and WSDL

PHPBuilder.com: Using PHP for the Creation of SVG Images


Community Events

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


language project symfony framework community composer list php7 part2 application opinion yii2 introduction podcast laravel example series voicesoftheelephpant api interview

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