Possible Duplicate:
Interface or abstract class?
I have a group of classes defined as follows:
namespace VGADevices.UsingAbstractClass
{
public abstract class VGA
{
public abstract int HorizontalResolution { get; set; }
public abstract int VerticalResolution { get; set; }
}
public class LCDScreen : VGA
{
public override int HorizontalResolution { get; set; }
public override int VerticalResolution { get; set; }
}
} // namespace VGADevices.UsingAbstractClass
namespace VGADevices.UsingInterfaces
{
public interface IVGA
{
int HorizontalResolution { get; set; }
int VerticalResolution { get; set; }
}
public class LCDScreen : IVGA
{
public virtual int HorizontalResolution { get; set; }
public virtual int VerticalResolution { get; set; }
}
} // namespace VGADevices.UsingInterfaces
Client code, I have the choice between:
class Computer
{
public VGA VGAOutput { get; set; }
}
or
class Computer
{
public IVGA VGAOutput { get; set; }
}
I read somewhere that using interfaces is better, but why? With abstract classes I can define an interface as well plus add data-members so why are interfaces the preferred method? Does binary replacement play a role here as well?
thank you
Chris