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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:06:09+00:00 2026-06-06T01:06:09+00:00

I am having following class hierarchy – //Abstract Class1 in library1 (Can’t modify this)

  • 0

I am having following class hierarchy –

//Abstract Class1 in library1 (Can't modify this)
public abstract class absClass1 : IDisposable
{
    public abstract int AddTwoNumbers(int Num1, int Num2);
    // Some other overrides, abstract methods and concrete methods

    void Dispose()
    {
       // Standard Dispose impl.
    }
}

//Abstract Class2 in library2
public abstract class absClass2 : absClass1
{
    //Implementing AddTwoNumbers
    public override int AddTwoNumbers(int Num1, int Num2)
    {
       return Num1+Num2;
    }

    public abstract int MultiplyTwoNumbers(int Num1, int Num2);

    // Some other overrides, abstract methods and concrete methods

    protected override void Dispose(bool disposing)
    {
        if (!IsDisposed)
        {
            //Cleanup
        }

        base.Dispose(disposing);
    }
}

//Derived class from absClass2 in library3
public sealed class absDerived1 : absClass2
{
    //Implementing MultiplyTwoNumbers
    public override int MultiplyTwoNumbers(int Num1, int Num2)
    {
       return Num1*Num2;
    }

    // Some other overrides, abstract methods and concrete methods

    protected override void Dispose(bool disposing)
    {
        if (!IsDisposed)
        {
            // Cleanup
        }

        base.Dispose(disposing);
    }
}

//... Some more implementation of absClass2 like absDerived2 etc.
//  can be there in other library4...

I want to dispose objects in both absClass2 and absDerived, is there any problem in overriding Dispose(bool) in both these classes? Is there any problem with this design? How can this be improved?

  • 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-06-06T01:06:11+00:00Added an answer on June 6, 2026 at 1:06 am

    This currently won’t compile, but as you aren’t asking why it doesn’t compile I’m going to guess you just left out the void Dispose() definition for brevity.

    This will be fine so long as you call into base.Dispose correctly and only worry about disposing the stuff local to the current class and not in a base class – as you are relying on base.Dispose to do this for you.

    Calling base.<member> simply calls the direct base type of the current type, so in your case absDerived goes to absClass2, which goes to absClass.

    My only observation would be you need to be careful on disposing the current type’s stuff before calling base.Dispose. Depending on how stuff relates, you might want to dispose the base stuff first, then the current type – but this is entirely dependent on what you are actually disposing and if order is important.

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

Sidebar

Related Questions

I have the following class hierarchy [BsonKnownTypes(typeof(MoveCommand))] public abstract class Command : ICommand {
I have a class hierarchy like this public abstract class CalendarEventBase{} public class TrainingEvent
I am having the following hierarchy: public class Small { private String xmlId; @XmlID
I have this base class having the following interface: abstract class Base { abstract
Having the following class: public class SomeClass { private readonly int[] _someThings; public SomeClass()
Having the following class (.Net 3.5): public class Something { public string Text {get;
Having the following classes, in two different assemblies: class Member { public string Label
I'm having the following scenario: class A { public static $arr=array(1,2); } class B
I'm having the following classes: class Base { public virtual void Print() { Console.WriteLine(Base);
I have a class hierarchy that can be simply put like this: struct Parent

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.