News Feed
Sections




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

Evert Pot's Blog:
Dangers of mutual dependencies
March 06, 2009 @ 13:42:40

In a recent post to his blog Evert Pot warns against some of the issues that mutual dependencies in your applications.

Much like most people, I try work out my class dependencies through a top-down 'waterfall'-ish approach. By attempting this, I think allows me to keep the structure very clear and understandable. [...] I try to apply the same model to instantiated objects and packages (groups of classes). When an object encapsulates another object, I attempt to make sure the sub-object object is not aware of the parent. When I design packages, I attempt to make sure 2 packages don't require 'each other'.

He gives an example of where this could cause problems - a Database logger that has three types of logging included: file, syslog and database. Obviously the last of the three requires the Database class so they must always be used/included together.

As a bonus a database-error could occur while logging, resulting in an endless loop (or segmentation fault if you're using PHP). [...] However, these types of situations are sometimes simply unavoidable (that's why we have include_once). When they are needed, they should be implemented with care and consideration.
0 comments voice your opinion now!
mutual dependencies dependent class database log example


blog comments powered by Disqus

Similar Posts

Dave Marshall's Blog: Traits in PHP 5.4 - HelloWorld with Logging Trait

PHPBuilder.com: Error Handling in PHP 5

Gennady Feldman's Blog: Performance tips, APC vs Eaccelerator

Paul Reinheimer: XHGui and MongoDB

DevShed: Performing Full-text and Boolean Searches with MySQL


Community Events





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


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

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