私は次のクラス階層を持っています-
//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)をオーバーライドすることに問題はありますか?このデザインに問題はありますか?これをどのように改善できますか?