abstract method use vs regular methods

前端 未结 6 1078
醉酒成梦
醉酒成梦 2021-01-13 06:45

I would like to know the difference between two conventions:

  1. Creating an abstract base class with an abstract method which will be implemented later on the der
6条回答
  •  终归单人心
    2021-01-13 06:46

    An abstract function can have no functionality. You're basically saying, any child class MUST give their own version of this method, however it's too general to even try to implement in the parent class. A virtual function, is basically saying look, here's the functionality that may or may not be good enough for the child class. So if it is good enough, use this method, if not, then override me, and provide your own functionality...

    And of course, if you override a virtual method, you can always refer to the parent method by calling base.myVirtualMethod()

提交回复
热议问题