A Final Few Words on Overridable Methods
Clearly, VB provides a lot of flexible keywords to make some interesting things happen when it
comes to inheritance and overridable methods. However, just because the language provides
them does not mean that it??™s wise to use them.
The Shadows modifier is a quick way to introduce some surprises into a class hierarchy. If
you ever find yourself using that modifier on a method, you??™re most likely using a class in a
way that it was not intended to be used. You could be deriving from a class that should have
been marked NotInheritable in the first place.
Properties
Properties are one of the nicest mechanisms within VB and the CLR that enable you to enforce
encapsulation. In short, you use properties to strictly control access to the internal state of an
object.
CHAPTER 4 n METHODS, PROPERTIES, AND FIELDS 77
A property, from the point of view of the client of the object, looks and behaves just like a
public field. The notation to access a property is the same as that used to access a public field
on the instance. However, a property doesn??™t have any associated storage space within the
object, as a field does. Rather, a property is a shorthand notation for defining accessors used
to read and write fields.
Pages:
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153