Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/
Kwic, As a question raised by paper in ACM in the early years, has been regarded by software design courses of various universities around the world as a class handout or assignment. (From wiki, FYI, D. l. parnas uses a kwic index as an example on how to perform modular design in his paper "on the criteria to be used in Decomposing systems into modules"-available as ACM classic paper)
1. Problem Description
Design and implement a Software System. The requirements are as follows:
Shows the main functions:
The software system specifies the Directory and file name of the English text file (.txt) to be processed and the Directory and file name of the output result file.
2. solution:
A. process-oriented solution:
See my previous article: http://blog.csdn.net/gnuhpc/archive/2009/10/03/4629466.aspx
Rating: This is the most simple implementation with poor scalability, but the program is simple and clear.
B. Basic object-oriented solutions:
This solution is a basic object-oriented solution with four basic functional classes: input, shift, alphabetize, and output. These functions are connected in the main program, the entire system is composed by sharing data.
The process is very simple. First, set the input/output path of the file through the input class and read the file to be processed. Then, shift is used to get the result of a row, in this case, alphabetizer is used to sort the first letter of these rows, and output is used.
A kwic class is designed to integrate the above classes. Code:
Bytes
Evaluation: each function module is designed separately. Permission control ensures encapsulation features and enhances system scalability and encapsulation.
C. Event-based notification solution:
The functions in the event-based notification system are not directly called, but triggered by setting up notifications or broadcasting event information. Other components can be linked by registering a process associated with an event notification. For example, our IDE is a typical system like this. The editor and variable monitor are associated with the breakpoint function of the debugger. When the debugger stays at a breakpoint, it automatically notifies its registered components to locate the code or observe the value of the variable.
Generally, there are two types of solutions. One is that the system has a separate event center, which is responsible for receiving all incoming information and distributing them to other components of the system, it can be a broadcast, or set a specific response for certain events.
This is often called: publish/subscribe, such
One solution does not set up a centralized event center. Each module allows other modules to declare what they need in the messages they send, in this way, messages sent by each module are sent only to the modules interested in this event, instead of to the Event Center.
This is often called observable/Observer, such
In the kwic system, we implement this event-based system as follows:
- Two Row-based storage modules: the first row-based storage module stores all original rows, and the second row-based storage module stores the modules after the cyclic shift. The input module is responsible for setting the path and reading from the input file and storing it in the first row storage module. The cyclic shift module is responsible for cyclic shift and is stored in the second row storage module. The output module is responsible for output to files, and the master module is responsible for the master process. When a row is added to the first row storage module, an event is triggered to be sent to the cyclic shift module. The cyclic shift module can process the row based on the event, store it to the second row storage module, which sends another event to the sorting module. The module will mix the newly added rows with the old ones and then sort them.
- The observable/observers mode is implemented. The event interaction includes two parts:
Register the shift loop module with the first row storage module. The shift module is the observer of the first row storage module.
Register the sorting module and the second row storage module. The sorting module is the observer of the second row storage module.
Java provides the observable class and observer interface for this mode,
The observer interface in Java. util provides convenience for the observer. Only one method needs to be implemented: update. This method is triggered when an event is received.
The observable class in Java. util provides convenience for the class for sending events. Instead, we can use it to provide methods for registering with the observer by other classes.
D. pipeline-based solution
In the pipeline-based solution, each component has a set of input streams and a set of output streams. One Component reads the data and sends the data to the next component after processing. This component is generally called filter. The connector is called pipes. Filters cannot share data and are independent of each other. The most famous similar program is the Unix shell.
Bytes
Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/