Possible Duplicate:
Interface 或 abstract class?
我的班级如下:
namespace VGADevices.UsingAbstractClass
{
public abstract class VGA
{
public abstract int H或izontalResolution { get; set; }
public abstract int VerticalResolution { get; set; }
}
public class LCDScreen : VGA
{
public override int H或izontalResolution { get; set; }
public override int VerticalResolution { get; set; }
}
} // namespace VGADevices.UsingAbstractClass
namespace VGADevices.UsingInterfaces
{
public interface IVGA
{
int H或izontalResolution { get; set; }
int VerticalResolution { get; set; }
}
public class LCDScreen : IVGA
{
public virtual int H或izontalResolution { get; set; }
public virtual int VerticalResolution { get; set; }
}
} // namespace VGADevices.UsingInterfaces
客户代码:我选择:
class Computer
{
public VGA VGAOutput { get; set; }
}
或
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