There can be many reasons for a common interface, IA and IB might have different properties and methods on other areas but if both of them somewhat defines a Matrix, a common interface would be great.
As a great programmer once said:
if possible Simplify everything to an
interface
I put together a solution which provides an example on what it might look like in the end
class Program
{
static void Main(string[] args)
{
// D derives from C which implements interface IA and IB which
// are both derived from IMatrix
var matrix = new D {Height = 100, Width = 200};
// Method takes IMatrix
X(matrix);
// Method takes IA
Y(matrix);
// Method takes IB
Z(matrix);
// Method takes D
LastTest(matrix);
//
// Prints heights and widths 4 times
//
}
static void X(IMatrix x)
{
Console.WriteLine(string.Format("Height: {0}\r\nWidth: {1}\r\n\r\n",
x.Height, x.Width));
}
static void Y(IA x)
{
Console.WriteLine(string.Format("Height: {0}\r\nWidth: {1}\r\n\r\n",
x.Height, x.Width));
}
static void Z(IB x)
{
Console.WriteLine(string.Format("Height: {0}\r\nWidth: {1}\r\n\r\n",
x.Height, x.Width));
}
static void LastTest(D x)
{
Console.WriteLine(string.Format("Height: {0}\r\nWidth: {1}\r\n\r\n",
x.Height, x.Width));
}
}
internal interface IMatrix
{
int Width { get; set; }
int Height { get; set; }
}
internal interface IA : IMatrix
{}
internal interface IB : IMatrix
{}
internal class C : IA
{
public int Width { get; set; }
public int Height { get; set; }
}
internal class D : IA, IB
{
public int Width { get; set; }
public int Height { get; set; }
}
In some occations you might just need the width and height, in other scenarios you might need the full set of IA or IB or even the implementation ( but that should be simplified to an interface aswell ).
However, don't over-engineer your software, think about the domain and try to extract common parts.
One might ask why you would have things that you Do not use, IMatrix might be a "bad name" but then you have another problem. Not used code = dead code and thus should be removed.