views:

31

answers:

2

I have a base class foo that will be used in multiple child classes of similar but slightly different function:

Public MustInherit Class foo
    Public Function bar1() as Something
        ''// Perfectly OK to change what this method does
    End Function

    Public Function bar2() as Something
        ''// Does a very specific thing I don't want changed ever,
        ''// but this function must be inherited
    End Function
End Class

How do I get the compiler to generate an error when bar2() is overridden by a child class?

+1  A: 

NotOverridable ?

mwilson
*(smacking forehead)* Google turned up nothing for me. Thank you!
Heather
+3  A: 

Specify the NotOverridable keyword in the function definition:

Public NotOverridable Function bar2() As Something
    ''// Does a very specific thing I don't want changed ever,
    ''// but this function must be inherited
End Function
Andy
It's been one of those days... thank you so much.
Heather
@Heather no problem :)
Andy