我有一个非常简单的场景:“人”可以是公司的“客户”或“员工”。
可以使用“呼叫”方法通过电话呼叫“人”。
根据“人”在通话中扮演的角色,例如新产品的发布或组织变更的声明,我们应该使用为“客户”角色提供的电话号码或提供的电话号码对于“员工”角色。
以下是情况的总结:
interface IPerson
{
void Call();
}
interface ICustomer : IPerson
{
}
interface IEmployee : IPerson
{
}
class Both : ICustomer, IEmployee
{
void ICustomer.Call()
{
// Call to external phone number
}
void IEmployee.Call()
{
// Call to internal phone number
}
}
但是此代码无法编译并产生错误:
error CS0539: 'ICustomer.Call' in explicit interface declaration is not a member of interface
error CS0539: 'IEmployee.Call' in explicit interface declaration is not a member of interface
error CS0535: 'Both' does not implement interface member 'IPerson.Call()'
这种情况是否有机会以不同的方式在 C# 中实现,还是我必须找到另一种设计?
如果是这样,您提出了哪些替代方案?
在此先感谢您的帮助。