我有以下类层次结构 -
//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...
我想同时在 和 中处理对象,absClass2
在absDerived
这两个类中覆盖 Dispose(bool) 有什么问题吗?这个设计有问题吗?如何改进?