My abstract base class implements an interface and a method like so:
public interface IFoo
{
void Bar();
}
public abstract class Foo : IFoo
{
public virtual void Bar()
{
throw new NotImplementedException();
}
}
Since the base class has no default implementation of this method and I can't make the method abstract, is it reasonable to let the base implementation throw or should it just return? What is the common approach to this? Thanks!
A1) If you are not implementing it in the base class, you should implements IFoo interface in the sub classes not the base class.
A2) If you do need to define a Bar method in the abstract class , then do not implement IFoo interface and all your sub classes will have the option toimplement Bar if required.
A3) Preferred one. Define the Bar method as abstract:
public abstract void Bar();
All your subclasses are forced to implement it.
Check:
http://www.dotnetperls.com/abstract