views:

174

answers:

1

Let's say I create a class "Planet" that can be inherited. One of the purposes of inheriting is to create a template with different default property values. Eg:

Public Sub New
    MyBase.New
    MyBase.ForeColor = Red
    MyBase.Name = "Mars"
    etc.
End Sub

Now, to stop the defaults serializing in the InitializeComponent method, there are 2 ways:

  1. If I've implemented the properties using the 'DefaultValue' attribute, and made them overridable, the attribute can be overriden with the new value. The problem with this is, there's no way to just make just the attributes overridable, as opposed to the whole property.

  2. I could implement every property with protected Reset'PropertyName' and ShouldSerialize'PropertyName' methods. However, this is a bit of a pain in the arse.

Is it, generally, an important consideration to ensure that someone who overrides your base class has the ability to change the default values of a property?

+1  A: 

I would say no. There is no way to guess up front if the deriver would even consider changing the default value. You will add code to your class that might never be used. Given that the deriver can change the default value (even though it is a pita), you should avoid adding unnecessary code.

Guidance for this is available from the WF implementation. It rarely does this.

Hans Passant