Client-Server Applications

In situations where an object window is created in a secondary thread to manipulate a data object such as a database, or to handle access to a remote device or system, it is often desirable to have a single object window performing the requested actions, in response to requests from multiple display windows. This follows the basic architecture of a client-server application, in accordance with the object-oriented rule of allowing access to a data object only from a single application object, and therefore implements the concept of encapsulation.

For example, a user may use different display windows to access different views of the same database. However, for reasons of efficiency and data integrity, the actual database access should be coordinated by a single object window, preferably in a secondary thread in case a database access request causes a lengthy search.

The question then arises of how the handle of the object window may be made available to multiple display windows. A number of options are available:

  • The handle may be stored as a global variable. This is not recommended however, since global variables are open to inadvertent modification, and their use imposes programming restrictions with respect to variable names.

  • Immediately after the object window is created, its handle may be passed to all display windows that require communication with the object window. However, if subsequent modification of the application introduces a new display window, additional modifications would be required to the module that created the object window. This increases the interdependence between application objects, and is therefore not recommended.

  • The handle of the object window may be stored in the window words of the application's main window. The handle of this window is available to all windows in the application, by querying the application's switch entry (as shown in Identifying the Destination Window). If the window words of the application's main window are used to store a pointer to a data structure, which in turn contains the handles of object windows and other items of a global nature, these items may be retrieved by window procedures when required.

    The final method described above is therefore the recommended solution. Object windows that will perform "server" tasks on behalf of a number of display window "clients" should be created by the window procedure for the application's main window, immediately upon creation of the main window, and the handles of the object windows stored in a data structure accessed via the window words of the main window.


    [Back: Preserving Data Integrity]
    [Next: Summary]