Do I need to update all the methods of an abstract class?

Younes Ch picture Younes Ch · Feb 18, 2013 · Viewed 14.9k times · Source

I need to inherit from a basic abstract class. I want to override only one method. But Visual Studio oblige me to override them all, So I am overriding more than 10 methods that throw NonImplementedException, I find it stupid. Isn't there any way to override only what I need. Or at least to tell Visual Studio to override the rest (non implemented methods and properties)?

The base class is written by the framework so I can't change it (I am talking about RoleProvider of ASP.NET MVC)

Answer

mihirj picture mihirj · Feb 18, 2013
abstract class Base
{
    public void Method1()
    { 
        //some code
    } // No need to override
    public abstract void Method2(); // must be overriden
    public virtual void Method3()
    {
        // some code
    } // Not necessarily be overriden
}

class Derived : Base
{
}

Here the compiler will only ask you to override Method2() as a mandate. It won't ask you to override Method1() or Method3(). You can override Method3() as it bears keyword virtual though.