The concrete structure of classes for our file server example is shown in figure 4. Intuitively, this BATCHING instance simply adds an interpreter (see the INTERPRETER pattern in ) to the file server. That interpreter can execute programs that (1) call read and write and (2) can use while as a control structure.
We took as an starting point the FileServer class, which provides both read and write methods to operate on a file.
We simplified the typical interface provided by a file server. A typical file server would contain several File objects that would supply read and write methods. To illustrate the pattern in a simple way, we omitted the file being used5.
The BatchFileServer is co-located with the FileServer, providing a new execute service that supplies an interpreted version of FileServer services. The BatchFileServer corresponds to the BatchServer in the pattern (see the pattern diagram in figure 3).
The BatchFileServer accepts a Program, which is built in terms of ControlStructures and Read and Write commands.
while (read(buf)) write(write(buf));the Program sent to the BatchFileServer must be made of a WhileCtrlStruct, using a Read as the condition. The body for the WhileCtrlStruct must be a sequence made of a single Write command.
Here, WhileCtrlStruct and SeqCtrlStruct correspond to ConcreteControlStructures in the pattern. Read and Write match Commands in the pattern. The buffer used in the read and write operations is handled by a BufferVar class instance, which corresponds to a ConcreteVar in the pattern.
A client can build a program (accessing the file server) by using constructors provided by WhileCtrlStruct, SeqCtrlStruct, Read, and Write. This batched call can be submitted later, by the client, to the execute method of the BatchFileServer.