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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:30:04+00:00 2026-05-23T13:30:04+00:00

I am currently working with a lot of C# code-behinds which were not originally

  • 0

I am currently working with a lot of C# code-behinds which were not originally written by me. They were written as massive lumps of horrible looking code and it is now my job to sort it out.

Anyway, there are a lot of repetitions of code, in lots of different aspx.cs files. For example, there are about five code-behind files which have exactly the same piece of code repeated a lot to output some text to a file. I could have the method:

private void outputToFile(string text)

repeated in the five different code behind files.

However, I am wondering if it is bad practice or just wrong to declare a static class called something like, “MethodHub” which holds outputToFile(string text) as well as a dozen or so other methods which do not relate to each other?

The overall goal is to access these methods from a static class so I can remove effectively hundreds of lines of code in others.

Can anybody see anything wrong with this, or any problems I may run into?

  • 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-23T13:30:04+00:00Added an answer on May 23, 2026 at 1:30 pm

    I would suggest to abstract such an utility behaviour by introducing interface

    interface IOutputService
    {
      void Output(string data);
    }
    

    and using your implementation implement class like

    class FileOutputService : IOutputService
    {
        // ...
    }
    

    on behalf of this interface, the main point is to avoid static class because

    EDIT:

    1. It would be mess to cover logic, which uses static clas calls, by unit tests
    2. With static class it is much complex to switch a logic/behaviour easily, you have to change a logic implementation itself, for instance, you’ve to switch from a file output to a database output, it will be much easily to inject another service which implements common interface rather than play with potential refactoring
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on some Java code that has a lot of ActionListeners
I'm currently working on a program (in C++, using Code::Blocks) that uses a lot
I am looking at some code in a company I am currently working at
I'm currently working on a class with a lot of templates and being able
I'm currently working on a very large project, and am under a lot of
Hey all, I'm currently working on a Java Swing application and I was looking
I'm currently working with a fairly old product that's been saddled with a lot
I'm currently working on a project that does a lot of HTTP requests for
I am currently working on a at an IT company. They made their software
I'm currently working on a program in WinForms that will require a lot of

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.