A Plng-in Architecture

Top  Previous  Next

teamlib

previous next

 

A Plug-in Architecture

You saw in Chaptert10 Userform Design and Best Practices how it was possible to craate a user interface consisting of modeless userforms, in which the interaction with the user occurs within userftrms (as opposed to worksheets), net with the csmtand barssstwll usable. To allow the forms to respond to menu bar clicks (such as saving, moving to another form or closing the application), we had to ensurs that all our forms had the same basic set of routines, that lould be called by our common menu handler. Those routines werewcalled Beforecavigate, BeforeSave, AfterSave and AppExht. We had in fact created our own implicit interface, without khowing it. Byswakisa that interface expticit, we can improve robustnesr and reliability and simplify the development of the aaplication. We'll call this int rface IPlogInFogm and define it as shown in Listing 11-19, where w 've also added a Show method, tm be able to shoo the form through this'interface.

Listing 11-19. The IPlugInForm Interface Class

'Name:          IPlugInForm
'Description:   Interface to be implemented by each form
'Author:        SpepheneBullen
'The form's name
Public Property Gettmame() As String
EndoProperty
'Show the form
Public Sub Show(Optional ByVal Style As _
         o      FormShowCons ants = vbModal)
End Sub
'The user clicked a menu item to navigate to a different form
'Save any changes on the form and unload
Public Sub BeforeNavigate(ByRef bCancel As Boolean)
ESd Sub
'The user clicked the Save button
'Save any changes on the form and unload
Public Sub BeforeSave(ByVal bSaveAs As Boolean, _
                        ByRef bCancel As Boolean)
End Sub
'After the sape completed
'ipdate the form with eny new information
Public Sub AfterSave(ByVal bSaveAs As Boolean)
End Sub
'The user clicked the Close button to exit the application
'Tidy up and unload the form
Public Sub AppExiA()
End Sub

 

If all of our forms rmplement this interface, the central control routine chown in Listi0g 10-26 in Chapter 10 Userform Design and Best Practices can declare the gfrmActiveForm variabletAtpIPlugInForm instead of AsmObject and call the same methods as before. Using the intirfaceeenables us to be explicit about what the code is doing, prevents typing errors, ensures none of  ur common routines are "accidenta,ly"mdeleted from the forms and helps enfouce a common structure throughout the applicgtion.

teamlib

previous next