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

  • Home
  • SEARCH
  • 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 6963541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:48:21+00:00 2026-05-27T15:48:21+00:00

I have 2 classes that have the exact same logic/workflow, except in one method.

  • 0

I have 2 classes that have the exact same logic/workflow, except in one method.

So, I created a abstract base class where the method that differs is declared as abstract.

Below is some sample code to demonstrate my design; can anyone offer suggestions on a better approach or am I heading in the right direction.
I didn’t use an interface because both derived classes B and C literally share most of the logic. Is there a better way to do what I am doing below via dependency injection?

public abstract class A
{
    public void StageData()
    {
        // some logic
        DoSomething();
    }
    public void TransformData();
    public abstract DoSomething();
}

public class B : A
{
    public override void DoSomething()
    {
        // Do Something!
    }
}

public class C : A
{
    public override void DoSomething()
    {
        // Do Something!
    }
}
  • 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-27T15:48:22+00:00Added an answer on May 27, 2026 at 3:48 pm

    There is nothing wrong with what you have done. To introduce dependency injection into this design would be messy and overkill – you would have to pass in a delegate:

    public class ABC
    {
        public ABC(Action z)
        {
            _doSomethingAction = z;
        }
    
        public void DoSomething()
        {
            _doSomthingAction.Invoke();
        }
    
    
        private Action _doSomthingAction;
    }
    

    There would be few reasons why you want to use this approach – one would be if you needed to execute a callback. So stick with the pattern you have, don’t try to overcomplicate things.

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

Sidebar

Related Questions

I have multiple classes that all derive from a base class, now some of
Imagine I have abstract base class Shape , with derived classes Circle and Rectangle
We have two classes that have the exact same public accessors (and many of
I have classes that are named exactly the same across different plug-ins that I
I have several classes that conceptually belong to one tier. They have no common
I've several databases that contains the exact same base tables with identical design. Now
I have a base class that has a private static member: class Base {
I have two very similar classes that do essentially the same thing. The only
Suppose I have a number of related classes that all have a method like
I have classes that store data, and methods to go get data for individual

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.