abstract classes and interfaces best practices in java

前端 未结 5 2321
无人及你
无人及你 2021-02-10 08:57

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:31

    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.

提交回复
热议问题