The Structure of Spring (Core)
Join the DZone community and get the full member experience.Join For Free
look, whatever you're doing: stop.
if you're at work, go home.
if you're at home, grab a beer from the fridge.
if you have dog, grab a beer for him, too.
banish the kids to their rooms.
send your husband out to get his hair done or your wife out to mend the car.
send your neighbours to the cinema.
because the girls and boys from spring are about to give you the greatest package-structure masterclass of your entire sorry-assed life.
note the time, because you'll want to look back at the moment when all your java projects' package-structures were suddenly rendered ugly, embarrassing and obsolete.
you are about to become a better person.
what had become a gloomy search for structural excellence among the the most popular, open-source, java programs slams into spring , the, " ... most popular application development framework for enterprise java." spring being too large to study as a single entity, this analysis will concentrate on the jar-file of the core components. (and thanks to @etiennestuder for suggesting spring as a candidate for analysis.)
as usual, we shall look at each release's package-structure as a spoiklin diagram in which a circle will represent a package, straight lines will represent dependencies from packages drawn above to those below and curved lines will represent dependencies from packages drawn below to those above. the colour of a package will indicate the relative number package-dependency tuples in which it partakes: the more red, the more dependency tuples.
seriously, hang on to something.
beginneth the enchantment.
figure 1: spring core version 0.9.
it all starts so well but if this series has taught us anything it is that most applications start well. figure 1 shows us the nine, well-structured packages of spring's core jar-file housing around eight hundred functions. pretty as a picture, it almost invites update so that we can effortlessly tip-toe along the ripple-effect paths.
so maybe a mutual dependency twangs between
but what's a single mutual dependency between friends?
figure 2: spring core version 1.0.
version 1.0 contains more-or-less the same number of functions as 0.9
but the number of packages increases from nine to eleven with that big,
barging into dominance, spraying dependencies far and wide.
still, stark order remains; even the
mutual dependency has vanished.
figure 3: spring core version 1.1.
figure 3 sees the number of functions rise to over a thousand and a third
package making an entrance, all gracefully absorbed by that resilient structure.
has developed a dependency on
is making eyes at
, to note a few of the changes, but nothing untoward disturbs the peace.
excellence of structure has now survived three significant upgrades; "not a bad record for this vicinity." fingers crossed that all goes well for whatever next mass influx of functionality that the spring engineers have in store.
figure 4: spring core version 1.2.
the number of functions shrivels to 369. some sort of year-zero-event, then. that code review must have been the mother of all bloodbaths.
not really much to say about this.
figure 5: spring core version 2.0.
version 2.0 returns to business as usual with almost nine hundred functions dolloped into ten packages and producing a structure which looks even better than that of the first version, 0.9.
the achingly-pretty simplicity finds itself reflected in two key statistics.
firstly, the structure is so wonderfully shallow with an average function-dependency tuple length of just 3.0 (std. dev. 1.6). depth ruins good structure, bulldozing all before it into the landfill of complication. indeed, depth had been a minor concern in version 1.1 which had an average function-dependency tuple length of almost ten - considered slightly high - but the great contraction of version 1.2 seems to corrected this trajectory: average dependency tuple length will never again rise above an impressively-low six.
secondly, as a direct consequence of the shallowness the number of function-dependency tuples composing the core components hovers at just over one thousand. this figure will become a concern again - we'll see that later - but to have the number of tuples so close to the number of functions strikes as an extraordinary feat of software engineering, producing one of the least-coupled designs this series has witnessed.
figure 7: spring core version 2.5.
version 2.5 maintains its structural composure even in the face of an extra nine packages and six hundred functions.
tracing potential ripple-effect paths remains a breeze. package-spotters
- up with the dawn mists, woolly-hatted, thermos-flasked - scribble to
record the excited arrival of the
package: it will
disappear immediately into those dawn mists and pop back up in version
3.2.0. where it will play a prominent role in the tuples-problem.
figure 8: spring core version 3.0.0.
version 3.0.0 accretes another three hundred functions, bringing the total to eighteen hundred, and sheds two packages, resulting in an almost-perfect crystalline structure. that such a vision represents a real-world, working-for-a-living, get-your-hands-dirty system rather than an ideal toy created in a structure tutorial belies belief.
beneath the surface, yet another key statistic enjoys improvement. the core components' configuration efficiency has to date languished at around twenty per-cent but this version sees it leap to thirty-four per-cent and it will rise slowly but steadily with each new upgrade.
figure 9: spring core version 3.0.5.
version 3.0.5 brings with it an extra two packages and one hundred and fifty functions. the result? continued, flawless structure.
figure 10: spring core version 3.1.0.
version 3.1.0. adds yet another three hundred functions, bringing the total to almost two thousand three hundred.
an ever-so slight blemish has appeared in those curved lines but these are mostly dismissible as drawing artifacts rather than indicators of deeper degradation. that the system maintains its integrity cannot be doubted.
figure 11: spring core version 3.2.0 with 4521 functions.
version 3.2.0 - last stop on our tour - represents by far the largest upgrade in the spring core components' history displayed here: the number of functions virtually doubles to four thousand five hundred while the number of packages soars to thirty-two.
yet how does this massive increase in functionality impact the structure? have the invading hoards brought the system to its knees?
not at all.
figure 11 radiates confidence and control and complete structural mastery.
the spring team has stood firm before the onslaught, battling the potentially-overwhelming functionality by simply expanding their structure to embrace it. the upshot is a configuration of packages that oozes decoupling and clarity-of-dependency. the aim of good structure is to aid update-cost prediction and figure 11 does precisely that.
facing such a diagram we all too easily lose sight of just what an accomplishment it represents. the secret of success lies in making the difficult look easy and in this the spring programmers have alas excelled themselves. without immediate comparison some might think that figure 11 is somehow normal in the field of software engineering, or even common.
this would be a mistake.
compare figure 11 to the ant package-structure, for example, when it grew to a similar number of functions:
figure 12: ant at 4603 functions.
the struts core components barely rose above three thousand functions yet recall that package-structure:
figure 13: struts core components at 3022 functions.
and junit never rose above thirteen hundred functions:
figure 14: junit at 1295 functions.
spring makes these look like crayon scrawls on padded walls.
not all roses.
but even spring has its problems.
though the package-structure thrived in the massive upgrade to version 3.2.0, a problem arose lower down: the number of function-level dependency tuples leaped from below four thousand in 3.1.0 to twenty-six thousand in 3.2.0. at the same time the number of function-level circular dependencies shot from below three hundred to above five thousand.
that rise in circular dependencies suggests that the proliferation of dependency tuples stems from some amplification effect; it would be a shame not to peek just a little closer to try to find evidence for such a claim.
and evidence there is. for when we look again we find that the function through which most dependency tuples flow is
package, a function whose cravat of immediate dependencies is shown in
figure 15 (in which circles represent functions rather than packages).
figure 15: classreader.accept()
from the naming scheme the experienced programmer immediately recognizes this as a visitor pattern which may go a long way towards explaining the problem: for such a dense concentration of dependencies offers a perfect nesting-ground for amplification effects.
package, in which this function resides, is a sink: it has no dependencies on any other packages in the core components.
both points suggest that the exorbitant number of dependency tuples - which might otherwise spoil the value of so fine a package structure - may be due not to systemic dependency disarray but a mere amplification-effect, one mostly confined to a single package.
on the whole, then, we can applaud this magnificent work for breath-taking structural achievement that it truly is. spring takes the top leader-board position and by an absurdly-long way.
thank you, spring.
just thank you.
Published at DZone with permission of Edmund Kirwan, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.