Prev | Current Page 192 | Next

Guy Fouch?©, Trey Nash

"Accelerated VB 2008"

In order to make the
CHAPTER 6 n INTERFACES 111
new Operation3() available, the DoWork() parameter type must change, or the code within it
must cast the argument to IMyOperations2, which could fail at run time. Since you want the
compiler to be able to catch as many type bugs as possible, it would be better if you changed
the DoWork() to accept a type of IMyOperations2.
nNote If you define your original IMyOperations interface within a fully versioned, strongly named
assembly, then you can get away with creating a new interface with the same name in a new assembly, as
long as the version of the new assembly is different. Although .NET supports this explicitly, it doesn??™t mean
you should do it without careful consideration because introducing two IMyOperations interfaces that differ
only by the version number of the containing assembly could be confusing to your clients.
That was a lot of work just to make a new operation available to clients. Let??™s examine the
same situation, except this time using a MustInherit class:
Public MustInherit Class MyOperations
Public MustOverride Sub Operation1()
Public MustOverride Sub Operation2()
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)
' Do ops
End Sub
End Class
MyOperations is the base class of ClientClass.


Pages:
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
dobrzybukmacherzy.info nobel calling cards fotele i krzesła biurowe wyciągarki kolokacja rack