I'm a little confused:
"however the compiler wont alow this"
Yes it will:
public abstract class Driver
{
public abstract void DoIt();
}
public class DDriver : Driver, IDisposable
{
public override void DoIt()
{
throw new NotImplementedException();
}
public void Dispose()
{
throw new NotImplementedException();
}
}
Compiles cleanly with no errors or warnings on my system (VS2010) as I would expect.
However, I would do it this way:
public abstract class Driver : IDisposable
{
public abstract void DoIt();
public abstract void Dispose();
}
public class DDriver : Driver
{
public override void DoIt()
{
throw new NotImplementedException();
}
public override void Dispose()
{
throw new NotImplementedException();
}
}
Because then you are forcing each derived class to implement IDisposable, which means that the abstract class variables can be used in
using
blocks irrespective of what eventual class they contain. If you implement IDisposable on one Derived class, then you have to check and convert each abstract class instance to see if it requires a Dispose call.