Using another interface


The Global Wizard program picks which conversion it wants to perform through some logic that we don’t care about, and sends the results to the following function:

Sub UpdateTargetFileDisplay()
HourGlass Me

‘ Select the appropriate filter and assign to any old object
Dim filterobj As Object
Select Case emtCur
Case emtStandard
If chkDelegate Then
‘ Translates standard module to global class with delegation
Set filterobj = New CModGlobDelFilter
Else
‘ Translates standard module to global class w/o delegation
Set filterobj = New CModGlobFilter
End If
Case emtClassPublic
‘ Translates public class to private class
Set filterobj = New CPubPrivFilter
Case emtClassGlobal
‘ Translates global class to standard module
Set filterobj = New CGlobModFilter
Case emtClassPrivate
‘ Translates private class to public class
Set filterobj = New CPrivPubFilter
Case Else
txtDst = ““
Exit Sub
End Select
‘ Setting name isn’t performance sensitive, so do it late bound
filterobj.Name = txtDstModName

‘ Use early-bound variable for performance sensitive filter
Dim filter As IFilter
Set filter = filterobj
filter.Source = txtSrc
FilterText filter
txtDst = filter.Target
HourGlass Me
End Sub

You might recall my saying at the start of this chapter that the Object type and late binding are evil, and yet look at the type of the filterobj variable at the top of this procedure. Call me a liar. Call me a realist. All these filter classes have a Name property, but it’s set only once. No one will be able to tell the difference if the class-specific objects are bound late rather than early. On the other hand, the properties and methods of the IFilter variable passed to FilterText will be called over and over. You’d notice the difference on large conversion operations if you passed a variable with Object type rather than IFilter type.