VB 10 thoughts (part 7)
Fri, Oct 12 2007 0:59
I've still got some more thoughts, but these are beginning to be big items, so I'm only touching on two more today
- Backing fields nested inside Properties
Public Property Name() As String
Dim m_Name As String
Set(ByVal value As String)
m_Name = value
In the above example the backing field is nested inside the property. This provides a lot more flexibility in the code editor experience as well as possibilities to limit the accessibility of the backing field. Typically you could access m_Name through-out the class. With this pattern that could be limited to only inside the property. This could be modified perhaps with an attribute, such as VisibleTo(VisibilityEnum), to indicate accessibility is the Property, Class, or PropertyAndConstructors. The later is useful for deserealisation when you want to set the backing fields only in constructors (or the property itself)
The nice thing about this pattern is it is compact. If you collapse the property the backing field is hidden, in fact it would look very much like a backed property short syntax, in fact it could be. With this syntax you can expand the property and set a break point on the property Set while not setting one on the property Get.
Although interesting, I'm not convinced of their real value. For VB they could raise a whole set of issues around interfaces. Still, when you do need/want them, they'd certainly come in handy.