Abstract class with all concrete methods

后端 未结 9 1309
感情败类
感情败类 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:04

    Immagine an interface whose declared methods usually show the same default behavior when implemented. When writing a class that needs to support the interface you have to define said default behavior over and over.

    To facilitate implementation of your concrete classes you might want to provide an abstract class providing default behavior for each method. To support the interface in a concrete class you can derive from the abstract class and override methods if they deviate from the standard behavior. That way you'll avoid the repeated implementation of the same (redundant) default behavior.

提交回复
热议问题