views:

22

answers:

2

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 :)

+1  A: 

Yes, this is perfectly acceptable. A MustOverride member 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 Protected is also a good idea as public virtual members can be problematic from a maintenance standpoint.

Andrew Hare
i assume just a little note explaining why and i should be ok, right?
Jason
A: 

As a step in your learning process, you should download .Net Reflector (from redgate).

Using it will tell you a lot about how others develop their code, and how Microsoft develops the framework code. You'll learn a lot from it.

Gabriel McAdams
yeah i have Reflector... good tool for sure. I wouldn't say I'm a noob at this, this is just the first time i've encountered this type of situation. but you are definitely right about .net reflector, thx :)
Jason