Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7817343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:12:14+00:00 2026-06-02T06:12:14+00:00

Our team has been given a legacy system for further maintenance and development. As

  • 0

Our team has been given a legacy system for further maintenance and development.
As this this is true “legacy” stuff, there is really, really small number of tests, and most of them are crap. This is an app with web interface, so there are both container-managed components as well as plain java classes (not tied to any framework etc.) which are “new-ed” here and there, whenever you want to.

As we work with this system, every time we touch given part we try to break all that stuff into smaller pieces, discover and refactor dependencies, push dependencies instead of pulling them in code.

My question is how to work with such system, to break dependecies, make code more testable etc? When to stop and how to deal with this?

Let me show you an example:

public class BillingSettingsAction {

    private TelSystemConfigurator configurator;
    private OperatorIdDao dao;

    public BillingSettingsAction(String zoneId) {
        configurator = TelSystemConfiguratorFactory.instance().getConfigurator(zoneId);
        dao = IdDaoFactory.getDao();
        ...
    }

    // methods using configurator and dao
}

This constructor definitely does too much. Also to test this for further refactoring it requires doing magic with PowerMock etc. What I’d do is to change it into:

public BillingSettingsAction(String zone, TelSystemConfigurator configurator, OperatorIdDao dao) {
    this.configurator = configurator;
    this.dao = dao;
    this.zone = zone;
}

or provide constructor setting zone only with setters for dependencies.

The problem I see is that if I provide dependencies in constructor, I still need to provide them somewhere. So it is just moving problem one level up. I know I can create factory for wiring all the dependencies, but touching different part of app will cause having different factories for each. I obviously can’t refactor all the app at once and introduce e.g. Spring there.

Exposing setters (maybe with default implementations provided) is similar, moreover it is like adding code for tests only.

So my question is how you deal with that? How to make dependencies between objects better, more readable, testable without doing it in one go?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T06:12:16+00:00Added an answer on June 2, 2026 at 6:12 am

    I’d try to establish a rule like the boy scout rule: When ever you touch a file you have to improve it a little, apart from implementing what ever you wanted to implement.

    In order to support that you can

    • agree on a fixed time budget for such improvements like for 2 hours of feature work we allow 1 hour of clean up.

    • Have metrics visible showing the improvement over time. Often simple things like average file size and test coverage are sufficient

    • Have a list of things you want to change at least for the bigger stuff, like “Get rid of TelSystemConfiguratorFactory” track on which tasks you are already working and prefere working on things that already started over new things.

    In any case make sure management agrees to your approach.

    On the more technical side: The approach you showed is is good. In many cases I would consider a second constructor providing all the dependencies but through the new constructor with the parameters. Make the additional constructor deprecated. When you touch clients of that class make them use the new constructor.

    If you are going with Spring (or some other DI Framework) you can start by replacing calls to static Factories with getting an instance from the Spring context as an intermediate step before actually creating it via spring and injecting all the dependencies.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Part of the development team I work with has been given the challenge of
Our team has been experiencing a recurring problem with velocity templates. Upon rendering, some
Our team has recently been working on a logic and data layer for our
Our team has recently been considering pushing out a minor registry fix to users
Our web team has been asked to build some user interfaces in Sharepoint. The
Our team has a task system where we post small incremental tasks assigned to
I'll try to make this as straight forward as possible. Currently our team has
My team has been asked to offer AMF output from our web service to
Our team has been asked to write a Web interface to an existing SQL
Our team has been using Microsoft's AJAX Toolkit since the days of Atlas. In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.