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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:25:33+00:00 2026-06-09T13:25:33+00:00

At my workplace there seems to currently be a crusade against static classes. I

  • 0

At my workplace there seems to currently be a crusade against static classes. I can understand part of that, they do sort of break the whole unit testing modularity thing. However, I am seeing an influx of code reviews that call for removing static classes.

A common case is a utility class this is spring-injected with a few other objects that are “known” at compile-time. It has no other member variables. If class M is calling this static class, I always see the suggestion to make this utility class non-static and inject it into class M.

This doesn’t make sense to me. I don’t particularly see anything wrong with it other than that it seems a waste of time and makes utility class less easily usable. As far as I can tell the justification is usually for unit testing, but I don’t like the idea that valid code has to be changed to conform to a testing paradigm. Admittedly mocking a simple static utility class would probably be overkill.

Are static classes appropriate in this use case, or best avoided?

  • 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-09T13:25:34+00:00Added an answer on June 9, 2026 at 1:25 pm

    I think the differences in the two approaches are small, but as long as the class contain no state it is slightly better to make it static. Let’s say I have this code in class A:

    StaticClass.utilMethod()
    

    If I want to use this code in class B I can copy and paste. That’s it. No adding member variables, injection, etc. cmd-c cmd-v.

    Considering your existing code uses static classes and modifying that will take work, it’s definitely best to continue using static classes.

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

Sidebar

Related Questions

Seems like there are no features in Sublime Text 2 that keep code folding
there is this check-in-out program here at my workplace, it only takes the data
There seems to be little documentation about this (unless I'm looking in the wrong
I am currently working on a feature that allows a user to determine which
At my workplace, the traffic blocker/firewall has been getting progressively worse. I can't connect
There seems to be a problem with ClickOnce deployments. The manifest file is executed
It seems that Apache ivy downloads artifacts only from http://mvnrepository.com/ and few other places,
Currently I have perforce that I am importing my project into eclipse from. After
My workplace uses XP and I was trying to run the following script on
My workplace filters our internet traffic by forcing us to go through a proxy,

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.