接口(Interface)
接口定義了所有類繼承接口時應遵循的語法合同。
接口定義了語法合同 "是什么" 部分侮繁,派生類定義了語法合同 "怎么做" 部分色徘。
定義接口
通常接口命令以 I 字母開頭
interface IMyInterface
{
void MethodToImplement();
}
接口繼承
interface IParentInterface
{
void ParentInterfaceMethod();
}
interface IMyInterface : IParentInterface
{
void MethodToImplement();
}
class InterfaceImplementer : IMyInterface
{
//實現(xiàn)
}