commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Reid Pinchback <>
Subject Re: [digester] initial code for Digester2.0
Date Tue, 01 Feb 2005 16:41:07 GMT

Sure thing.  Just to make it easier to envision, let's get
packages out of the equation.  Just think about cyclic
dependencies between two classes in the same package.
That is enough to show the problem; packages just add complexity 
because the dependencies can be much harder to detect visually 
(usually you would use something like JDepend to spot them) 
and harder to unwind.

Refactoring is harder simply because you have to do a larger
number of smaller steps.  Doesn't mean impossible, more steps
just mean more work, more time, more money.  Tricky enough when 
only two classes are involved, harder as the number of classes 
involved in the cycle increase.  Get enough classes involved, 
and you start to hear statements like "it will be easier to 
throw that away and start over again than it will be to fix it".

class A {
  int a;
  int fooA(int arg) {
    // 1a. do stuff with {B.fooB,a,arg}
    // 2a. do other stuff with result and {a}

class B {
  int b1, b2;
  int fooB(int arg) {
    // 1b. do stuff with {A.fooA,b1,arg}
    // 2b. do other stuff with result and b2
    // 3b. do stuff with {A.fooA,b2,arg}

Refactoring remains possible, but tricky because
you have both compile-time code dependencies and
run-time state dependencies.  You are faced with 
things like factoring out small fragments of code 
into helper classes, and maybe introducing an 
interface to at least eliminate the compile-time
dependency between A and B, even if the run-time
dependency remains.  

Often the solution ends up something like

a) make interface I
b) create class C implements I
   and migrate some of A and B state into C
c) modify A and B to share I

It works, it just takes time... and often you
are doing it before even trying to tackle whatever
bug or feature enhancement you were faced with
in the first place.

Do you Yahoo!? 
Take Yahoo! Mail with you! Get it on your mobile phone. 

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message