Cyclic Dependencies: Clean the Up!

September 14th, 2008

Cyclic dependencies are a challenge for any build system and code to handle. But I you look closely at cyclic dependencies, in most if not all cases they are a structural problem and not a technical problem. Cyclic dependencies indicate in most cases either that two modules belong together or one module implements two tasks.

Let’s take a projcect I am currently working on. There are two modules, the Interpester and the Object Manager, both are cyclic dependent. The Interpreter implements a virtual machine. The Object Manager implementes object serialisation and low level buissness logic. The basic contollflow is as follows: Object Manager calls Interpreter to evaluate some value and to do this the Interpreter calls back into the Object Manager get values to a given object.

If you read the above paragraph cloasly you will notice that the Object Manager implements “object serialisation and low level buissness logic”. Well as you can see there are two tasks that can and should be split in two seperate modules. If they are split in three modules there are no cyclic denendencies.