我应该在 child 中实现父亲接口吗?
Should I implement father interface in the child?
如果我正在编写一个继承自另一个实现接口的 class,我应该在 child 中实现这个接口吗?
class FatherClass implements MyInterface
{
...
}
public class ChildClass extends FatherClass { // Should I implement MyInterface here?
...
}
- Parent class 中实现的接口只是继承
- 因此无需将 "implements SomeInterface" 复制并粘贴到子 class 上。没必要,聪明点。
- 让子项和父项都实现相同的接口没有额外的效果。
- 相当于让父级只实现那个接口。
如果我正在编写一个继承自另一个实现接口的 class,我应该在 child 中实现这个接口吗?
class FatherClass implements MyInterface
{
...
}
public class ChildClass extends FatherClass { // Should I implement MyInterface here?
...
}
- Parent class 中实现的接口只是继承
- 因此无需将 "implements SomeInterface" 复制并粘贴到子 class 上。没必要,聪明点。
- 让子项和父项都实现相同的接口没有额外的效果。
- 相当于让父级只实现那个接口。