A Plug-in ArchitectureYou saw in Chapter 10 Userform Design and Best Practices how it was possible to create a user interface consisting of modeless userforms, in which the interaction with the user occurs within userforms (as opposed to worksheets), yet with the command bars still 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 ensure that all our forms had the same basic set of routines, that could be called by our common menu handler. Those routines were called BeforeNavigate, BeforeSave, AfterSave and AppExit. We had in fact created our own implicit interface, without knowing it. By making that interface explicit, we can improve robustness and reliability and simplify the development of the application. We'll call this interface IPlugInForm and define it as shown in Listing 11-19, where we've also added a Show method, to be able to show the form through this interface. Listing 11-19. The IPlugInForm Interface ClassIf all of our forms implement this interface, the central control routine shown in Listing 10-26 in Chapter 10 Userform Design and Best Practices can declare the gfrmActiveForm variable As IPlugInForm instead of As Object and call the same methods as before. Using the interface enables us to be explicit about what the code is doing, prevents typing errors, ensures none of our common routines are "accidentally" deleted from the forms and helps enforce a common structure throughout the application. |