I did not fully understand using Interfaces, so I have to ask 🙂
I use a BaseClass, which implements the IBaseClass interface.These interface only contains one declaration :
public interface IBaseClass
{
void Refresh ();
}
So I have implement a Refresh method in my Baseclass :
public void Refresh ()
{
Console.WriteLine("Refresh");
}
Now I want to use some classes which extends from these Baseclass and implements the IBaseClass interface :
public class ChildClass : BaseClass,IBaseClass
{
}
But cause of the implementation of “Refresh” into my BaseClass I does not have to implement the method again. What should I do, to force the implementation of “Refresh” into all childs of BaseClass as well as all childclasses of childclass.
Thanks kooki
You cannot force derived classes to re-implement the method in the way that you have specified. You have three options:
refreshin the base class. The interface will force child classes to implement it.abstractas well asrefresh, for which you would not give an implementation.refreshin the base class asvirtual. This allows overrides but will not force them. This is howToString()works.This is all assuming that your base class is larger than a single method. If indeed your code is exactly what you posted then Oded’s answer is the best choice.