Abstract class with all concrete methods

后端 未结 9 1311
感情败类
感情败类 2020-12-08 21:49

Are there some practical programming situations for someone to declare a class abstract when all the methods in it are concrete?

相关标签:
9条回答
  • 2020-12-08 22:20

    An abstract class is a class that is declared abstract - it may or may not include abstract methods. They cannot be instantiated so if you have an abstract class with concrete methods then it can be subclassed and the subclass can then be instantiated.

    0 讨论(0)
  • 2020-12-08 22:28

    Well you could be using a template method pattern where there are multiple override points that all have default implementations but where the combined default implementations by themselves are not legal - any functional implementation must subclass.

    (And yes, I dislike the template method pattern ;))

    0 讨论(0)
  • 2020-12-08 22:29

    When you have an important class but the system cannot create an instance fo this class, because

    • this class is parent of a lot of classes of the system;
    • this has a lot of responsability (methods used by a lot of class) for domain's requires;
    • this class not represents a concrete object;
    0 讨论(0)
提交回复
热议问题