abstract classes and interfaces best practices in java

前端 未结 5 2103
一个人的身影
一个人的身影 2021-02-10 08:37

So you\'ve got an interface and an abstract class that implements a subset of the methods in the interface. You\'ve also got some classes that inherit the abstract class and giv

5条回答
  •  梦谈多话
    2021-02-10 09:29

    Do you have more implementations of the interface than the abstract class or subclasses thereof? Do your design need the interface? Otherwise, the interface contributes nothing to your design, and I suggest you simply get rid of it.

    When it comes to your explicit questions, the abstract class should implement the interface. Classes extending the abstract class shouldn't.

    You shouldn't redundantly declare abstract methods in the abstract class that already is in the interface.

提交回复
热议问题