Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Inheritance 没有方法的子接口_Inheritance_Design Patterns_Interface - Fatal编程技术网

Inheritance 没有方法的子接口

Inheritance 没有方法的子接口,inheritance,design-patterns,interface,Inheritance,Design Patterns,Interface,所以我有一个父接口,还有一些子接口,一些有实现,一些没有 interface IParent { void A(); void B(); } interface IChild1 : IParent { void C(); } interface IChild2 : IParent { // empty, just inherits } 这是好的做法吗?如果没有,那么更好的方法是什么?通过引入一个没有任何新方法的接口,您希望实现什么?我有一个接口,其中包含许多

所以我有一个父接口,还有一些子接口,一些有实现,一些没有

interface IParent {
    void A();
    void B();
}

interface IChild1 : IParent {
    void C();
}

interface IChild2 : IParent {
    // empty, just inherits
}

这是好的做法吗?如果没有,那么更好的方法是什么?

通过引入一个没有任何新方法的接口,您希望实现什么?我有一个接口,其中包含许多子接口的常用方法,但在这种情况下,子接口将没有任何具体的实现方法。在代码的其他部分中,我总是引用子接口,因此不创建它会导致直接引用基类,可能会提供如何使用子接口的示例。如果空接口只是为了让您的代码更具可读性-好吧,但它不寻常,其他阅读您的代码的人可能会想:-)。