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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:50:59+00:00 2026-05-26T10:50:59+00:00

I have some debugging functions that I would like to refactor, but seeing as

  • 0

I have some debugging functions that I would like to refactor, but seeing as they are debugging functions, it seems like they would be less likely to follow proper design. They pretty much reach into the depths of the app to mess with things.

The main form of my app has a menu containing the debug functions, and I catch the events in the form code. Currently, the methods ask for a particular object in the application, if it’s not null, and then mess with it. I’m trying to refactor so that I can remove the reference to this object everywhere, and use an interface for it instead (the interface is shared by many other objects which have no relation to the debugging features.)

As a simplified example, imagine I have this logic code:

public class Logic
{
    public SpecificState SpecificState { get; private set; }
    public IGenericState GenericState { get; private set; }
}

And this form code:

private void DebugMethod_Click(object sender, EventArgs e)
{
    if (myLogic.SpecificState != null)
    {
        myLogic.SpecificState.MessWithStuff();
    }
}

So I’m trying to get rid of the SpecificState reference. It’s been eradicated from everywhere else in the app, but I can’t think of how to rewrite the debug functions. Should they move their implementation into the Logic class? If so, what then? It would be a complete waste to put the many MessWithStuff methods into IGenericState as the other classes would all have empty implementations.

edit

Over the course of the application’s life, many IGenericState instances come and go. It’s a DFA / strategy pattern kind of thing. But only one implementation has debug functionality.

Aside: Is there another term for “debug” in this context, referring to test-only features? “Debug” usually just refers to the process of fixing things, so it’s hard to search for this stuff.

  • 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-26T10:51:00+00:00Added an answer on May 26, 2026 at 10:51 am

    Create a separate interface to hold the debug functions, such as:

    public interface IDebugState
    {
        void ToggleDebugMode(bool enabled); // Or whatever your debug can do
    }
    

    You then have two choices, you can either inject IDebugState the same way you inject IGenericState, as in:

    public class Logic
    {
        public IGenericState GenericState { get; private set; }
        public IDebugState DebugState { get; private set; }
    }
    

    Or, if you’re looking for a quicker solution, you can simply do an interface test in your debug-sensitive methods:

    private void DebugMethod_Click(object sender, EventArgs e)
    {
        var debugState = myLogic.GenericState as IDebugState;
        if (debugState != null)
            debugState.ToggleDebugMode(true);
    }
    

    This conforms just fine with DI principles because you’re not actually creating any dependency here, just testing to see if you already have one – and you’re still relying on abstractions over concretions.

    Internally, of course, you still have your SpecificState implementing both IGenericState and IDebugState, so there’s only ever one instance – but that’s up to your IoC container, none of your dependent classes need know about it.

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

Sidebar

Related Questions

I have some debugging code that looks like the following: #define STRINGIFY(x) #x #define
I have some debugging code that if executed while running with GBD attached should
I have some code in MS VC++ 6.0 that I am debugging. For some
I have some UI in VB 2005 that looks great in XP Style, but
While debugging a client app that uses a Google backend, I have added some
Debugging experience http://www.dmhermitage.org/wtfborders.png This is making me want to kill myself. I have some
I am debugging some code and have encountered the following SQL query (simplified version):
I'm debugging a network application. I have to simulate some of the data exchanged
I have some ASP.NET web services which all share a common helper class they
We have some input data that sometimes appears with &nbsp characters on the end.

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.