Abstract Methods versus Virtual Methods
Both (abstract methods and virtual methods) offer similar functionality – when should you use virtual methods and when should you use abstract methods?
Base Functionality Driven
If you want a base behavior as the default behavior and allow child behavior to override it – then use virtual methods. If you want to leave the base behavior un-defined – and have child classes take on full responsibility for implementing that behavior – use abstract methods (this comes with the drawback of forcing your entire class to be abstract).
Performance Driven
Virtual methods have slower performance.
Abstract methods are virtual by default
Abstract methods are by default virtual – since they MUST be overridden.
Containing Classes
A class that contains an abstract method (even a single one) – has to be marked as abstract. However, if a class contains virtual methods, it can be concrete.
Leave a Reply