|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV SYS-CON.TV WEBCASTS |
POWERBUILDER LINKS YOU MUST CLICK ON Feature Working with Legacy Applications
An example of building a mock-up object
Feb. 26, 2008 08:15 AM
When I realized that I was going to be dealing with legacy code a lot more than I would be creating new applications, I was a bit disappointed. However, as time passed I found that working with legacy applications can be just as interesting, and even adventurous. In this article I'd like to tell you about a mock-up object - an object that looks like a real one, behaves like a real one, but doesn't actually perform the functions of the real object being mimicked. I'll tell you about how I decided to create a mock-up object and integrate it into one of the legacy applications I had worked on, and what the results were. I'll explain how I used the mock-up objects and what pitfalls lie in wait for a developer integrating them into legacy applications. Please note that in this article I use UML-like diagrams, which in general are not always formally correct UML diagrams. However, I kept UML 2.0 in mind when I was drawing them.
Annoyance
How the Thing Was Done The of_open_port and of_close_port functions are examples of those functions communicating with a printer. The of_build_labelA and of_build_labelB represent the functions that produced ZPL-commands strings, and the of_print function actually sent the command string into the port. As you probably know, the typical interaction with uo_bc_print involved two steps: a client called one of the functions that built a command string and then this string was passed to the of_print function. An example of such an interaction is shown in Figure 2. It's clear from Figure 2 that the user object uo_bc_print was strongly dependent on the communication library; many of its functions called the external functions from wsc32.dll, such as SioDSR and SioPutC called by of_print. Each time the object was used, it tried to communicate with a barcode printer. This is what I was going to change.
Options to Consider A quick search on the Internet showed that it was hardly possible to find free serial port emulation software that would suit my needs and, even if I found something, it would require some effort to configure it properly (meaning I had to know which answers the external functions expected from a printer - but I didn't). I gave up this option. I considered the second option; the biggest flaw in it was that the user object changed from time to time (existing labels were modified and new labels were added) and I really hated the idea of synchronizing my "dummy" copy with the actual version in the future. So I decided to focus on the third option - the programmer way.
The Programmer Way The simplified structure of the new objects and their relation is shown in Figure 3. The u_nv_bc_comport_impl object contains calls of the external functions from wsc32.dll; in fact, all its functions simply redirect the calls to the external function. The u_nv_bc_comport_mock object does not call the functions from wsc32.dll. Initially I thought I would leave the function empty and not have a separate object at all and just use either u_nv_bc_comport_impl or u_nv_bc_comport. Then I decided that it would be nice to have a debug window that would display the strings that were sent to the printer. The functions of u_nv_bc_comport_mock do exactly this. The uo_bc_print object has an instance variable iuo_comport of the u_nv_bc_comport type. The idea was that soon after the creation of uo_bc_print, it would read the configuration setting, for example, from the Windows Registry, saying whether to use a barcode printer or emulate interaction with it. If a printer was to be used, uo_bc_print would create an instance of u_nv_bc_comport_impl and place the reference to it into iuo_comport. If a printer was to be emulated, uo_bc_print would create an instance of u_nv_bc_comport_mock and place the reference to it into iuo_comport. I placed the code that created a needed object into the uo_bc_print Constructor event script:
string ls_value All calls of the function from wsc32.dll inside uo_bc_print were replaced with calls of the corresponding functions of iuo_comport. As a result, only u_nv_bc_comport_impl was dependent on wsc32.dll. I could now use uo_bc_print without any problems during development without a barcode printer (along with u_nv_bc_comport_mock) and in production with a barcode printer (along with u_nv_bc_comport_impl). Nice job! PBDJ LATEST STORIES . . .
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK BREAKING POWERBUILDER / SYBASE NEWS
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||