I need to have a multiple Form classes in my project. So was thinking about putting everything those forms will have in common, together in abstract class. This class will have inheriet Form class and also an interface. Sth like that:
public interface IMyForm
{
void Init();
}
public abstract class AMyForm : Form, IMyForm
{
void IBrowser.Init()
{
throw new NotImplementedException();
}
}
public partial class MainClass : AMyForm
{
// But here the warning is shown (That i have to add override keyword),
// but when i do, The error is shown that i cannot override from non abstract thing
public void Init()
{
}
}
Could u tell me how to achieve that ?
You just want to not use explicit interface implementation in your abstract class:
Or just make it abstract:
In both cases, you then just override it in your concrete class.
Alternatively, if you really want to use explicit interface implementation in your abstract class, you should use it again in your concrete class:
The downside is that any subclass of
AMyFormwhich doesn’t do this will basically have the brokenIMyFormimplementation. Using the first approach is better here.EDIT: Or, as per supercat’s suggestion:
Then override
InitImplin your concrete class.