News Feed
Jobs 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

Sebastian Bergmann's Blog: Test Dependencies in PHPUnit 3.4

IBM developerWorks: Going dynamic with PHP

Community News: Ottawa Food Bank Improve Distribution Databases via PHP

DevShed: Defining a Model Class for Handling Views with CodeIgniter

Matthew Turland's Blog: Log Analysis and PHP


Community Events











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


series unittest overview release symfony2 component application facebook security language hhvm introduction framework package composer install podcast opinion hack code

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