Thursday, 4 April 2013

Private virtual methods

During review of my patch, reviewer mentioned that  private virtual methods make very little sense.  Then I've asked few more people and all of them have similar opinion that it is better not to use them.

But I think private virtual method make code more clear in following case: if we do not need to  invoke virtual function from derived classes, but only customize  the behaviour, then function can be private.

And we immediately get profit: only by looking on base class definition we can gain information about  class behaviour.

UPD
Something mixed up in my head :) By making virtual function in base class private we only forbid to derived classes call base version of virtual function.