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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:51:50+00:00 2026-05-27T00:51:50+00:00

I have a design issue. I am modifying existing code and where I was

  • 0

I have a design issue. I am modifying existing code and where I was instantiating new class. It’s giving me errors due to turning the class into a Abstract class which I can understand. It’s throwing an error because you can’t create instances of abstract class.

I had this code below

ExampleProcessor pro = new ExampleProcessor();

but the ExmapleProcessor class is now turned into abstract class.

public abstract class ExmapleProcessor {
  public abstract void Method1();
  public abstract void Method2();
}

Child classes AExampleProcessor and BExampleProcessor.

public class AExampleProcessor : ExampleProcessor 
{  
  public override void Method1()  { //do something }
  public override void Method2()  { //do something }
}

public class BExampleProcessor : ExampleProcessor 
{
  public override void Method1()  { //do something }
  public override void Method2()  { //do something }
}

So this line is causing 42 errors “ExampleProcessor pro = new ExampleProcessor();” everywhere in my application.

I dont want to do

AExampleProcessor pro = new AExampleProcessor();

and

BExampleProcessor pro = new BExampleProcessor();

because I want my application to decide which class to use. How can I make it so it loads up the correct class?

I would like code examples please..

  • 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-27T00:51:50+00:00Added an answer on May 27, 2026 at 12:51 am

    Create a factory:

    public static class ExampleProcessorFactory
    {
       public static ExampleProcessor Create()
       {
           if(IsFullmoon)
               return new ExampleProcessorA();
           else
               return new ExampleProcessorB();
       }
    }
    

    Then replace all calls to new ExampleProcessor() with calls to ExampleProcessorFactory.Create(). Now you’ve encapsulated the instantiation logic and the choosing of what concrete class to instantiate into one place where you can apply any logic to decide what class to instantiate. (The logic of deciding when to use which class might benefit from some improvement to be unrelated to the full moon.)

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

Sidebar

Related Questions

I've ran into a design issue; in a project, i have three tables: League,
I have the following SQL design issue. The code below might look a little
I've run into an interesting design issue with a class library I am writing.
I have a design issue that I would appreciate some input on. I would
I have an issue with some inheritance I'm doing. Basically, I have an abstract
i have a design issue regarding sending user data from a mobile phone app
I have a prickly design issue regarding the choice of database technologies to use
I seem to run into a couple of design issue a lot and I
In a system for managing vocational training, I have a CourseBase abstract class, which
I have a design issue. I need to implement a listener. I saw the

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.