软件体系结构经典问题——KWIC的分析和解决

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

软件体系结构经典问题——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把所有⾏的各种移位情况按照字母表顺序输出
•⽬的:考察不同的体系结构对变化的适应能⼒(modifiab ility)
•评价准则
–处理算法的改变:例如,⾏的移位可在每⾏读⼊后、在所有⾏读⼊后、或当排序要求⼀组移位的⾏时執⾏;
–数据表⽰的改变:例如,⾏、字、字符可以不同的⽅式存储;类似地,循环移位后的⾏可以显式或隐式存储(索引和偏移量);
–系统功能的增强:例如,限制以某些“修饰词”(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. 数据结构的设计必须在其他模块设计开始之前进⾏
⽅案优缺点:
+系统⾃然分解,符合⼈的处理习惯
+数据共享,处理效率⾼
+
–难以适应数据存储格式和整体处理算法的变化——爲什麽?
–系统构件难以⽀持复⽤——爲什麽?
仔细参考:。

相关文档
最新文档