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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:19:33+00:00 2026-05-13T17:19:33+00:00

Sorry if this sounds simple, but I’m looking for some help to improve my

  • 0

Sorry if this sounds simple, but I’m looking for some help to improve my code 🙂

So I currently have the following implementation (which I also wrote):

public interface IOptimizer
{
    void Optimize();
    string OptimizerName { get; }
}

public abstract AbstractOptimizer : IOptimizer
{
    public void Optimize()
    {
        // General implementation here with few calls to abstract methods
    }
}

public abstract AbstractPriorityOptimizer : AbstractOptimizer 
{
     // Optimize according to priority criteria.    

     string Name 
     { 
        get { return "Priority Optimizer"; }
     }      
}

Then I have technology-specific concrete classes:

TechnologyXPriorityOptimizer : AbstractPriorityOptimizer 
TechnologyYPriorityOptimizer : AbstractPriorityOptimizer 

Now I’m trying to add a generic optimizer, one that optimizes for conditions other than priority, so my attempt:

public abstract AbstractGenericOptimizer : AbstractOptimizer 
{
     // Optimize according to a generic criteria.    

     private readonly int param;

     public AbstractGenericOptimizer (int param) : base()
     {
          // param affects the optimization
          this.param = param;
     }        
}

and I also need technology-specific implementation just like the priority optimizer:

TechnologyXGenericOptimizer : AbstractGenericOptimizer 
TechnologyYGenericOptimizer : AbstractGenericOptimizer 

Q1. TechnologyXPriorityOptimizer and TechnologyXGenericOptimizer have the same exact “extra” methods because they involve the same technology. Is there a way to keep this method common to both inheritance branches ?

Q2. For AbstractGenericOptimizer, the optimizer has a special name for special values of the int param, so would it be a good idea to extend the base generic optimizer class (where param is hardcoded) and then for every division, have a technology-specific implementation:

AbstractSpecialName1Optimizer: AbstractGenericOptimizer
TechnologyXSpecialName1Optimizer: AbstractSpecialName1Optimizer
TechnologyYSpecialName1Optimizer: AbstractSpecialName1Optimizer

AbstractSpecialName2Optimizer: AbstractGenericOptimizer
....

What would be the best way to refactor this scenario ? I feel that there is a smarter way of reducing the number of inheritance levels.

Thanks!

  • 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-13T17:19:33+00:00Added an answer on May 13, 2026 at 5:19 pm

    You should probably use containment instead of inheritance.

    For example, you could make an abstract OptimizerStrategy class with concrete implementations for each technology, then make the GenericOptimizer and PriorityOptimizer take an OptimizerStrategy as a generic type argument or constructor parameter.

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

Sidebar

Related Questions

Sorry if this question sounds a little silly, but I am not sure what
Sorry if the title sounds confusing - but this is what I am trying
sorry this is such a simple question but I can't figure it out. How
Sorry for this simple question, but I can't solve it... There is an example:
Sorry if this sounds obvious but i'm getting confused. I'm trying to build a
Sorry if this sounds like a really silly question. But I Googled the web
This sounds like a relatively simple question, but I haven't been able to get
Sorry if this sounds like a newbie question, but the other day a Java
I am sorry if this is a really simple question but I am really
Sorry if this has been covered - I've been looking for hours but I

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.