I have a base windows forms class which contains two buttons: Ok and Cancel. This base form implements the interface IBaseForm:
public interface IBaseForm
{
string FormText {get;set;}
DialogResult ShowView(IWin32Window owner);
}
public partial class BaseForm : IBaseForm
{
...
}
Next I have a window class which inherits from BaseForm and implements another interface IItem:
public interface IItem : IBaseForm // here is problem
{
string ItemName {get; set;}
...
}
public partial class AddItemForm : BaseForm, IItem
{
...
// I don't have to implement IItem here, because it is implement in BaseForm
}
The problem is with the inheritance of IBaseForm; I have to inherit it two times.
In code I have:
IItem view = new AddItemForm();
view.FormText = "Add new item";
If I remove inheritance from IItem, view.FormText will be not visible. If I remove the inheritance from BaseForm I have to implement IBaseForm in each AddItemForm. I’ve only showed one itemForm but it is a lot, and I have to implement this many times.
How I can resolve this problem?
There isn’t another way to do this. BaseForm is a class, whereas IItem is an unrelated interface. Neither is a ‘super’ or ‘base’ of the other, so you need to inherit from IBaseForm in both of them.