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 972699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:09:52+00:00 2026-05-16T03:09:52+00:00

I’m working on a project with a large existing codebase and I’ve been tasked

  • 0

I’m working on a project with a large existing codebase and I’ve been tasked with performing some re-engineering of a small portion of it. The existing codebase does not have a lot of unit testing, but I would like at least the portion I’m working on to have a full suite of unit tests with good code coverage.

Because the existing codebase was not designing with unit testing in mind, I need to make some structural changes in order to support isolation of dependencies. I’m trying to keep the impact on existing code as small as possible, but I do have a bit of leeway to make changes to other modules. I’d like feedback on whether the changes I’ve made make sense or if there is a better way to approach the problem. I made the following changes:

  1. I extracted interfaces for all of the non-trivial classes on which my ‘coordinator’ class depends. The other developers grudgingly allowed this, with some minor grumbling.

  2. I modified the coordinator class to refer only to the interfaces for its operation.

  3. I could not use a DI framework, but I had to inject a large number of dependencies (including additional dependency instantiation as part of the class operation), so I modified the coordinator class to look like this (domain-specific names simplified):

.

public sealed class Coordinator
{
    private IFactory _factory;

    public Coordinator(int param)
        : this(param, new StandardFactory())
    {            
    }

    public Coordinator(int param, IFactory factory)
    {
        _factory = factory;
        //Factory used here and elsewhere...
    }

    public interface IFactory
    {
        IClassA BuildClassA();

        IClassB BuildClassB(string param);

        IClassC BuildClassC();
    }

    private sealed class StandardFactory : IFactory
    {
        public IClassA BuildClassA()
        {
            return new ClassA();   
        }

        public IClassB BuildClassB(string param)
        {
            return new ClassB(param);
        }

        public IClassC BuildClassC()
        {
            return new ClassC();
        }
    }
}

This allows for injection of a stubbed factory to return the mocked dependencies for unit testing. My concern is that this also means any user of this class could supply their own factory to change the way the class operates, which is not really the intention. This constructor is purely intended for unit testing, but it has the side effect of implying that additional extensibility was intended. I don’t usually see this pattern in other classes I use, which makes me wonder if I’m over-complicating and if there’s a better way to achieve the required isolation.


NOTE: There’s something weird going on with the code formatting, so I apologize for the poor formatting above. Not sure why it won’t let me format it correctly.

  • 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-05-16T03:09:52+00:00Added an answer on May 16, 2026 at 3:09 am

    The proposed design is a variant of Constructor Injeciton sometimes known as Bastard Injection. In a greenfield situation I would consider Bastard Injection an anti-pattern, but it’s a good compromise in a brownfield situation like the one you describe.

    You shouldn’t really be concerned about the implied extensibility of the Coordinator class. Done correctly, testability is extensibility, so ideally the injected IFactory should represent a proper Domain Concept that enables variability. I understand that this can be difficult/impossible to achieve at a single stroke when you’re refactoring from legacy code, but that’s the direction in which your code base should be moving.

    In any case, if your coworkers already begrudge the extraction of interfaces, they are probably not very likely to interpret the IFactory constructor parameter as an extensibility point.

    Good luck.

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

Sidebar

Ask A Question

Stats

  • Questions 501k
  • Answers 501k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Updates in hibernate are implemented using dirty checking rather than… May 16, 2026 at 2:23 pm
  • Editorial Team
    Editorial Team added an answer You could add a column to the datatable, and set… May 16, 2026 at 2:23 pm
  • Editorial Team
    Editorial Team added an answer Maybe these two sentences do convey intuitively the distinction between… May 16, 2026 at 2:23 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I have just tried to save a simple *.rtf file with some websites and
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.