[英]Multiple inheritance of interfaces
我的任务是实现具有以下属性的接口IPerson和Person类:
Title
Name
DateOfBirth
Age
实现一个接口IDetails
和类Details
,该接口继承自IPerson
和具有以下属性的Person
类:
Religion
National Insurance Number
我的问题是,如何对接口进行多重继承? IPerson如何从IDetails继承/派生?
从技术上讲, IDetails
扩展了 IPerson
,但从概念上讲,它类似于继承:
public interface IPerson
{
string Title {get; set;}
string Name {get; set;}
int DoB {get; set;}
int Age {get; set;}
}
public interface IDetails : IPerson
{
int Religion {get; set;}
int NationalInsuranceNumber {get; set;}
}
现在,任何实现 IDetails
类IDetails
必须为IDetails
和 IPerson
所有成员提供一个实现。
一个示例实现为:
public class PersonWithDetails : IDetails
{
public string Title {get; set;}
public string Name {get; set;}
public int DoB {get; set;}
public int Age {get; set;}
public int Religion {get; set;}
public int NationalInsuranceNumber {get; set;}
}
请注意,一个类可以实现多个接口,但只能从一个基类继承 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.