News Feed

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

Knut Urdalen's Blog: ORM the manual way

SitePoint PHP Blog: 3 Lightweight Alternatives to phpMyAdmin

DevArticles: Building an AJAX-Based Chat - Interacting With a Database

Felix Geisendorfer's Blog: Enforce utf8 for multiple db connections PHPSpec: BDD for your classes

Community Events

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

package series library community framework interview version symfony voicesoftheelephpant update language release introduction tool composer opinion mvc laravel podcast security

All content copyright, 2014 :: - Powered by the Solar PHP Framework