[英]Multiple inheritance of interfaces
I was tasked with implementing an interface IPerson and class Person that has the following properties: 我的任务是实现具有以下属性的接口IPerson和Person类:
Title
Name
DateOfBirth
Age
Implement an interface IDetails
and class Details
that inherits from IPerson
and class Person
that has these properties: 实现一个接口
IDetails
和类Details
,该接口继承自IPerson
和具有以下属性的Person
类:
Religion
National Insurance Number
My question is, how can I do multiple inheritance for interfaces? 我的问题是,如何对接口进行多重继承? How can IPerson inherit/derive from IDetails?
IPerson如何从IDetails继承/派生?
Technically IDetails
extends IPerson
, but conceptually it's similar to inheriting: 从技术上讲,
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;}
}
Now any class that implements IDetails
must provide an implementation for all members of IDetails
and IPerson
. 现在,任何实现
IDetails
类IDetails
必须为IDetails
和 IPerson
所有成员提供一个实现。
An example implementation would be: 一个示例实现为:
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;}
}
Note that a class can implement multiple interfaces but can only inherit from one base class. 请注意,一个类可以实现多个接口,但只能从一个基类继承 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.