This week's giveaway is in the Spring forum.
We're giving away four copies of Microservices Testing (Live Project) and have Chris Love & Andres Sacco on-line!
See this thread for details.
Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Introducing DI in legacy code

 
Ranch Hand
Posts: 105
Android Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

I often work with clients / legacy code where Spring or Guice, i.e. DI, is not used. I really like the DI principle because it enforces loosely coupled code and thus makes my code more readable and testable. What would be a good strategy / argument to introduce a DI framework in the legacy code case? Refactor bit by bit and attack it from the service & unit test layer? Big bang? Any experience with introducing DI in legacy code?

Cheers,

Johan
 
Ranch Hand
Posts: 471
Mac OS X Hibernate Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would certainly go for the bit by bit refactoring. Big Bang, as you put it, is really risky, will take a lot work time with no real difference that appears to the client. The Big Bang option might be useful if you are in a stage where no new features are asked to be added to the legacy code, and you are in a stage where code cleaning and refactoring is the main target.
 
author
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Certainly not big-bang.

Yes I have introduced it in a couple of applications from the ground up. The key is to start with the parts of code that are changing the most, then work your way outward. That way your immediate pain is eased a bit, and everyone on the team is using DI regularly and gets comfortable with it.

There are lots of compelling reasons in the political fight, you essentially have the good ones though: modularity, testability, loose coupling and reduction of error-prone boilerplate code.
 
The longest recorded flight time of a chicken is 13 seconds. But that was done without this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic