軟件體系結構經典問題——KWIC的分析和解決


KWIC作為一個早年間在ACM的Paper提出的一個問題,被全世界各個大學的軟件設計課程奉為課堂講義或者作業的經典。(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)

問題陳述:KWIC(Key Word In Context),Parnas (1972)
      KWIC索引系統接受一些行,每行有若干字,每個字由若干字符組成;每行都可以循環移位,亦即重復地把第一個字刪除,然后接到行末; KWIC把所有行的各種移位情況按照字母表順序輸出
 
目的: 考察不同的體系結構對變化的適應能力(modifiability)
評價准則
處理算法的改變:例如,行的移位可在每行讀入后、在所有行讀入后、或當排序要求一組移位的行時執行;
數據表示的改變:例如,行、字、字符可以不同的方式存儲;類似地,循環移位后的行可以顯式或隱式存儲(索引和偏移量);
系統功能的增強:例如,限制以某些“修飾詞”(a, an, and等)打頭的移位結果;支持交互,允許用戶從原始輸入表中刪除一些行等;
效率:時間和空間;
復用:構件被復用的潛力。
 
Solution 1
Main Program/Subroutine with Shared Data
Elements of Main/Subroutine Architectural style are:
  • Components: Functions
  • Interactions: Function calls
  • Pattern: Main function controls the calling sequence
This is the primary organization of many software systems. This style reflects structural/procedural programming language (e.g. C programming language) in which these system are written.
 
 
Decompose the overall processing into a sequence of processing steps.
Read lines; Make shifts; Alphabetize; Print results
Each step transforms the data completely.
每一步完全轉換數據
Intermediate data stored in shared memory.
Arrays of characters with indexes
帶索引的字符數組
Relies on sequential processing
串行處理
 
Solution 1 Modularization
Module 1: Input
Reads data lines and stores them in core .
Storage format: 4 chars/machine word; array of pointers to start of each line.
Module 2: Circular Shift
Called after Input is done.
Reads line storage to produce new array of pairs: (index of 1st char of each circular shift, index of original line)
Module 3: Alphabetize
Called after Circular Shift.
Reads the two arrays and produces new index.
 
Module 4: Output
Called after alphabetization and prints nicely formatted output of shifts
Reads arrays produced by Modules 1 & 3
Module 5: Master Control
Handles sequencing of the first 4 modules
Handles errors
 
Properties of Solution 1
Batch sequential processing.
Uses shared data to get good performance.
用共享數據獲得性能
Processing phases handled by control module.
So has some characteristics of main program – subroutine organization.
Depends critically on single thread of control.
Shared data structures exposed as inter-module knowledge.
共享數據的結構是所有模塊必須知道的
Design of these structures must be worked out before work can begin on those modules.
數據結構的設計必須在其他模塊設計開始之前進行
 
方案優缺點:
+系統自然分解,符合人的處理習慣
+數據共享,處理效率高
+
–難以適應數據存儲格式和整體處理算法的變化——爲什麽?
–系統構件難以支持復用——爲什麽?
 
仔細參考:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM