This may put complicated
restrictions upon your client code. For example, what if one of your clients needs to create an
object for use with .NET remoting? To do so, the class must derive from MarshalByRefObject,
so it can??™t inherit from MyOperations.
Sometimes, it??™s tricky to find a happy medium when deciding between interfaces and
classes. Use the following rules of thumb:
??? If modeling an is-a relationship, use a class: If it makes sense to name your contract with
a noun, then you should probably model it with a class.
??? If modeling an IMPLEMENTS relationship, use an interface: If it makes sense to name
your contract with an adjective, as if it were a quality, then you should probably model
it as an interface.
??? Consider packaging your interface and MustInherit class declarations in a separate assembly:
Implementations in other assemblies can then reference this separate assembly.
??? If possible, prefer classes over interfaces: This can be helpful for the sake of extensibility.
CHAPTER 6 n INTERFACES 113
Polymorphism with Interfaces
Throughout this chapter, you??™ve seen that different types that implement the same interface can
be treated as the same type. Let??™s look more closely at how interfaces support polymorphism:
Public Interface IGeometricShape
Sub Draw()
End Interface
Public Class Rectangle
Implements IGeometricShape
Public Sub Draw() Implements IGeometricShape.
Pages:
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206