In a base class object, I have an overridable subroutine that I would like all derived objects to have the ability to include. However, they don’t have to, and if it’s not necessary for them to use it, I don’t want them to be forced to declare it. To enforce this, I’ve left the default behavior empty. For example, here’s my whole sub:
Protected Overridable Sub MySubroutine(ByVal someObject As Object)
End Sub
Is this bad practice? I don’t want to declare it as MustOverride, but I don’t want default behavior. Is there a “better” way of doing this, or is this perfectly acceptable? I don’t want to be that hack programmer… just trying to learn 🙂
Yes, this is perfectly acceptable. A
MustOverridemember can often be too strict of a requirement for an inheriting class so if you want a virtual member without default implementation this is the proper thing to do.Anyone who is inheriting from this class will appreciate the fact that you have defined a virtual member as a “hook” into your class like this. Also the fact that you have declared this method as
Protectedis also a good idea as public virtual members can be problematic from a maintenance standpoint.