Home > Articles > Web Services > XML

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

Façade Pattern—Repackaging the Legacy Code

Not only is it good practice to reuse code; we also get to use the façade pattern, which provides a design framework for accessing the legacy code. The façade in this case is the structure used to call into the SNMP API from the new program. In fact, the façade pattern should always be used when calling into any external subsystem (such as ODBC). This helps if you later decide to change the technology of the external subsystem.

In fact, operating system code has been written this way for decades, where platform-specific code is located in blocks of assembler code. Then, if the operating system is ported to another platform, it is theoretically only the assembler code that needs to be changed.

Listing 3 illustrates the means by which the program façade.exe accesses the legacy network management code. A single class (netMgmtEngine) provides a method netMgmtAccess(), which calls into the legacy C code.

Listing 3 Facade Pattern for Network Management Access (netMgmtEngine.h)

class netMgmtEngine
   void netMgmtAccess(int, char **);

Two parameters are passed to netMgmtAccess(): a count of string elements and a single string containing a corresponding set of string objects. An example of calling this is the following:

netMgmtAccess (5, "WALK MyHostPC public .iso.org.dod.internet.mgmt.mib-2.interfaces");

This parameter set supplies five elements: the program name, the program mode (WALK), the host name, the SNMP community name ("public"), and the required SNMP object ID. The result should be a list of managed object instances that represents the entire set of interfaces on the platform called "MyHostPC" (as we'll see in Listing 4).

  • + Share This
  • 🔖 Save To Your Account