Insulating Your Projects from Further Change

Visual Basic 4 and later versions let you write your projects as a series of ActiveX components. Visual Basic 5 lets you move further down this route with the ability to add and create your own controls.

This approach has many advantages, including increasing the amount of code reuse. (See Chapter 15 on code reuse.) Its major advantage from a maintenance programming perspective is that each component deals with differing parts of the environment that your program has to operate in. When a part of that environment changes, if the elements of your program that communicate with the part of the environment are contained in a small component, your rework and testing is limited.

Future versions of ActiveX components such as Word will change. How will these changes affect your existing applications? At this stage, you cannot know. How can you insulate your applications from these changes? By wrapping up any code that performs tasks with these ActiveX servers. For instance, one application I worked on had three servers, one a wrapper to talk to Crystal Reports, one to talk to Microsoft Word, and one to talk to a U.S. Robotics Palm Pilot (not via ActiveX). When these applications change their ActiveX wrappers, the inner workings might need to change but their public interfaces will not.

To do your printing, you might rely on Crystal Reports for your reports displaying statistical information. Additionally, you can use Word to display well-presented views of the data for a single object. At the time this book went to press, there are two versions of Word that you are likely to find on a user’s machine, and there will soon be three. Word 6, Word 7, and Word 8. Word 8 promises a new, more-structured ActiveX verb structure. This is different from Word 6’s and 7’s flat ActiveX models. And again, there are differences between Word 6 and 7. There are at least two ways you can work around this. You can choose to test the version and act accordingly; or you can, as we do at TMS, wrap your calls to Word in an ActiveX server, which exposes a few methods to your core application and installs an appropriate version of the ActiveX server. To maintain your application, all you need to do is modify the internals of your ActiveX server to allow for changes in components you are dependent on. Your front-end program can then call your servers without modification.