1. Field of the Invention
The invention relates generally to the field of data storage in computer systems and, more specifically, to a technique for applying the command pattern to facilitate communication between a client and server.
2. Description of the Related Art
In the standard client/server application design, the client passes first data to the server. The server then interprets the first data, manipulates it to obtain second data, and returns the second data back to the client. The client then interprets that second data. However, this requires all the logic for interpreting and manipulating data to be contained within the server, making the server less flexible when trying to change its functionality. Moreover, the server must also know about all types and versions of clients that can connect to it so it can properly handle the data in ways the different clients will understand. Furthermore, if a new client type is added, the server must be updated by a software update to support the client, and old servers cannot support the new client if they cannot be updated, e.g., due to hardware limitations such as processor speed and memory capacity.
To address these and other issues, the present invention describes a technique for facilitating communication between a client and server using the command pattern.
In a particular aspect of the invention, a method for use by a client host in providing a networked application with a server host includes using a command pattern to encapsulate instructions and first data into a command object, and providing the command object to the server host, wherein the server host executes the instructions in the command object to provide second data, based on the first data, in the command object, and returns the command object with the second data to the client host.
A corresponding program storage device is also provided
In another aspect of the invention, a method is provided for use by a server host in providing a networked application with a client host. The method includes receiving a command object from the client host, wherein a command pattern is used by the client host to encapsulate instructions and first data into the command object, executing the instructions in the command object to provide second data, based on the first data, in the command object, and returning the command object with the second data to the client host.
These and other features, benefits and advantages of the present invention will become apparent by reference to the following text and figures, with like reference numbers referring to like structures across the views, wherein:
The general operation and configuration of the processors 110, 160, memories 105, 155, network interfaces 115, 165, and database 170, is well known in the art and is therefore not described in detail. The components illustrated are provided to assist in understanding the invention. The hosts 100, 150 may be general-purpose computers, workstations, servers, portable devices such as PDAs, or other computer devices. The functionality described herein can be achieved by configuring the hosts 100 and 150 with appropriate software. In one approach, the software comprises an object-oriented software such as Java code that is stored in the memories 105, 155. In this case, the memories 105, 155 are program storage devices. The software is executed using the processors 110, 160 in a known manner.
The invention solves the problem described at the outset by applying the command pattern to the client/server application. The command pattern is an object-oriented design pattern that describes a pattern for encapsulating instructions and data into a single object, called a command. A command can be passed around to different components of a software application, and then executed as needed. Components that receive a command can execute the command without knowledge of the data or the purpose of the command. The command pattern may be applied in a graphical user interface (GUI), for instance. For example, an application might request a user to input their address information as first data at a client host. The application presents a window containing fields for the user to input, such as name, address, state, etc. Once the user has input the data, the user presses a submit button to submit the data. In this application, the command pattern could be used to store that first data. When the submit button is pressed, a submit command would be created. The data input by the user would be placed in the submit command, then the submit command would be sent to another part of the software, such as at a server host, for processing. The other software starts the execution of the command, providing the necessary resources, such as access to a database, for this example. The command then executes its instructions, using the data supplied from the user and the resources provided by the software.
The benefit is that a different command, say a command to retrieve data from the database, can be executed by the same piece of software that provides access to the database. This can be achieved by sending a command object from the client to the server, instead of just raw data. The command object contains data, as well as the instructions to process the data. When the server receives the command object from the client, it simply executes the command instructions, then returns the command itself back to the client with new data. This encapsulates the new data within the command, and the client can then find the appropriate data for the command it sent. Advantageously, platform-specific instructions need not be used.
Moreover, the server does not need to know anything about the raw data it receives from the client. If a new client type is added, the server does not need modification since the client will still be sending commands that the server can execute. If the data being sent to the server needs to be changed for any reason, the server does not need to be updated to support the new data. The invention allows for flexibility in the client/server application by allowing new client types and versions to be added that can still communicate with old servers. This can be understood by noting that a command is an abstract data type, in this case, an object. The server knows how to process commands, in the abstract sense. It receives a command, executes it (passing any necessary resources in), then sends the command back. A new command could be created that the server never saw before, yet the server could still handle it and process it, even if the server does not know anything about the clients.
A practical example of using the command pattern in a client/server application is in the context of a company phone book application. The application could be a piece of client software that resides on an employee's computer as the client. When an employee wishes to lookup a phone number of a colleague, the employee enters the colleague's name into the local client application. The application then creates a command object with instructions such as “obtain the phone number of an employee”, and first data such as the employee's name. The application sends the command object as a request to a centralized database server, which contains all employee phone numbers. The colleague's number is found and returned to the employee making the request. In particular, the server executes the instruction “obtain the phone number of an employee” and processes the first data in the command object to look up the employee's phone number based on the employee's name in the database 170. The server thus processes the first data based on the instructions to provide second data, e.g., the employee's phone number. The employee's phone number is included in the command object and returned to the client. The client then interprets and processes the second data in the returned command object, e.g., by displaying the employee's phone number on a display.
In this example, there are two pieces of software. One is the client application, which allows for user input and displays results, and the other is the server database software, which accepts requests, looks up the information, and sends the results back.
Example pseudo code for this application (using Java syntax) would be as follows:
The first file would define the Command from a high level. The interface Command could be as follows:
Specific command objects are required to do specific actions. In this case, we are doing a lookup, so we could have a lookup command as follows:
The server software to process the command could be as follows:
The client software could be as follows:
Now, assume that the company wants to allow its employees to update their own phone numbers in the database. They could release second client software for doing updates. In order to do updates, a new command would be needed, as follows:
A new client application could be written as follows:
This new command could be supported by the server without requiring any code changes to the server. And, the same server can be used by both client types without needing to differentiate between them.
The invention has been described herein with reference to particular exemplary embodiments. Certain alterations and modifications may be apparent to those skilled in the art, without departing from the scope of the invention. The exemplary embodiments are meant to be illustrative, not limiting of the scope of the invention, which is defined by the appended claims.