- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
执行初始化的例子
5.2.2 Cohesion(内聚) The degree of interaction within a module Seven categories or levels of cohesion (non-linear scale) (1) Coincidental Cohesion(偶然内聚) A module has coincidental cohesion if it performs multiple, completely unrelated actions (如果一个模块执行多个完全不相关的操作,则具有偶然内聚) Example(为了达到规定的语句数而将不相关的几个操作安排在一个模块内的例子) print_next_line, add_7_to_fifth_parameter, convert_fourth_parameter_to_ floating_point Such modules arise from rules like “Every module will consist of between 35 and 50 statements” (如果规定了诸如“每个模块必须由35-50个语句构成”这样的限制,则容易产生偶然内聚的模块) Why Is Coincidental Cohesion So Bad? It degrades maintainability(可维护性退化) A module with coincidental cohesion is not reusable (不可重用) The problem is easy to fix Break the module into separate modules, each performing one task (2) Logical Cohesion (逻辑内聚) A module has logical cohesion when it performs a series of related actions, one of which is selected by the calling module (当一个模块进行一系列相关的操作,每个操作由调用模块来选择时,该模块就具有逻辑内聚) Logical Cohesion (contd) Example 1(调用模块new_operation如下:) function_code = 7; new_operation (op code, dummy_1, dummy_2, dummy_3); // dummy_1, dummy_2, and dummy_3 are dummy variables, // not used if function code is equal to 7 Why Is Logical Cohesion So Bad? The interface is difficult to understand Code for more than one action may be intertwined(纠缠) Difficult to reuse (3) Temporal Cohesion(时间内聚) A module has temporal cohesion when it performs a series of actions related in time (当模块执行一系列与时间有关的操作时,该模块具有时间内聚) Example(执行初始化的例子) open_old_master_file, new_master_file, transaction_file, and print_file; initialize_sales_district_table, read_first_transaction_record, read_first_old_master_record (a.k.a. perform_initialization) Why Is Temporal Cohesion So Bad? The actions of this module are weakly related to
文档评论(0)