One advantage is that MyOperations can
contain default implementations if it wants to, though it doesn??™t do that here. Now, suppose
you want to add a new Operation3 method to MyOperations, and you don??™t want to break existing
clients. You can do this as long as the added operation is not MustOverride, such that it
forces changes on derived types, as shown here:
CHAPTER 6 n INTERFACES 112
Public MustInherit Class MyOperations
Public MustOverride Sub Operation1()
Public MustOverride Sub Operation2()
Public Sub Operation3()
'Do op 3
End Sub
End Class
Public Class ClientClass
Inherits MyOperations
Public Overrides Sub Operation1()
' Do op 1
End Sub
Public Overrides Sub Operation2()
' Do op 2
End Sub
End Class
Public Class AnotherClass
Public Sub DoWork(ByVal ops As MyOperations)
ops.Operation3()
End Sub
End Class
Notice that the addition of Operation3() to MyOperations doesn??™t force any changes upon
ClientClass, and AnotherClass.DoWork() can use Operation3() without making any changes
to the parameter declaration. This technique doesn??™t come without its drawbacks, though.
Since a class can have only one direct base class, ClientClass has to derive from MyOperations
to get the functionality, so it uses up its only inheritance ticket.
Pages:
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205