【问题标题】:Should I implement father interface in the child?我应该在孩子中实现父亲接口吗?
【发布时间】:2015-04-30 08:37:12
【问题描述】:

如果我正在编写一个从另一个继承的类,它实现了一个接口,我应该在孩子中实现这个接口吗?

class FatherClass implements MyInterface
{
    ...
}

public class ChildClass extends FatherClass { // Should I implement MyInterface here?
    ...
}

【问题讨论】:

  • 你的意思是你应该像public class ChildClass extends FatherClass implements MyInterface一样声明它?

标签: oop inheritance interface


【解决方案1】:
  • Parent 类中实现的接口只是继承
  • 因此无需在子类上复制和粘贴“implements SomeInterface”。没必要,更聪明。
  • 让子级和父级都实现相同的接口不会产生额外的影响。
  • 相当于让父级只实现该接口。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-04
    • 2015-01-20
    • 1970-01-01
    • 2010-09-17
    • 2013-09-15
    相关资源
    最近更新 更多