下面的代码是否存在架构问题?就是所谓的diamond problem可能与接口(interface)或类似问题有关?
interface IComponent
{
void DoStuff();
}
interface ITitledComponent : IComponent
{
string Title { get; }
}
abstract class ComponentBase : IComponent
{
public void DoStuff()
{
throw new NotImplementedException();
}
}
class MyComponent : ComponentBase, ITitledComponent
{
public string Title => throw new NotImplementedException();
}
当然,类的菱形继承是一个错误的决定,这在 C# 中是不可能的。但是关于接口(interface)我没有找到资料。
最佳答案
不,用 C# 不可能产生菱形问题,因为您只能从一个类继承。接口(interface)不是继承的,而是实现的。因此,编译器和编码器的实际问题永远不会发生,即拥有一个方法的两个实现并且不知道为特定类选择哪个。
关于c# - C# 中的接口(interface)是否可能出现菱形问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52697629/