私には非常に単純なシナリオがあります。「人」は会社の「顧客」または「従業員」になることができます。
「人」は「電話」方式で電話でかけることができます。
新製品の発表や組織変更の発表など、通話のコンテキストで「人」が果たす役割に応じて、「顧客」の役割に提供された電話番号または提供された電話番号のいずれかを使用する必要があります。 「従業員」の役割。
これが状況の要約です:
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#で別の方法で実装できる可能性がありますか、それとも別のデザインを見つける必要がありますか?
もしそうなら、あなたはどのような選択肢を提案しますか?
よろしくお願いします。