Coupling and Cohesion 2

本文探讨了软件设计中模块间的耦合与内聚概念,分析了不同类型的耦合从最不理想到最理想的排列,并介绍了内聚强度的等级划分。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Coupling and Cohesion

extracted from Timothy Budd's An Introduction to Object-Oriented Programming

[Words in square-brackets are my additions to what Budd wrote. -- S. Bloch]

"Coupling" describes the relationships between modules, and "cohesion" describes the relationships within them. A reduction in interconnectedness between modules (or classes) is therefore achieved via a reduction in coupling. On the other hand, well-designed modules (or classes) should have some purpose; all the elements should be associated with a single task. This means that in a good design, the elements within a module (or class) should have internal cohesion.

Coupling between modules can arise for different reasons, some of which are more acceptable, or desirable, than others. A ranked list [from least desirable to most desirable] might look something like the following:

  • Internal data coupling [one module modifying the internals of another]
  • Global data coupling [modules sharing global data]
  • Control or sequence coupling [one module controlling the sequence of events in another]
  • Parameter coupling [one module passing information to another through parameters]
  • Subclass coupling [one module inheriting from another]

...

As with coupling, cohesion can be ranked on a scale of the weakest (least desirable) to the strongest (most desirable) as follows:

  • Coincedental cohesion [elements are in the same module for no particular reason]
  • Logical cohesion [elements perform logically related tasks]
  • Temporal cohesion [elements must be used at approximately the same time]
  • Communication cohesion [elements share I/O]
  • Sequential cohesion [elements must be used in a particular order]
  • Functional cohesion [elements cooperate to carry out a single function]
  • Data cohesion [elements cooperate to present an interface to a hidden data structure]

...

One can often estimate the degree of cohesion within a module by writing a brief statement of the module's purpose.... The following tests are suggested by Constantine:

  1. If the sentence that describes the purpose of the module is a compound sentence containing a comma or more than one verb, the module is probably performing more than one function; therefore, it probably has sequential or communicational binding [or even less: temporal, logical, or coincedental]
  2. If the sentence contains words relating to time, such as "first," "next," "then," "after," "when," or "start," the module probably has sequential or temporal binding. An example is "Wait for the instant teller customer to insert a card, then prompt for the personal identification number."
  3. If the predicate of the sentence does not contain a single, specific object following the verb, the module is probably logically bound. For example, "Edit all data" has logical binding; Edit source data may have functional binding.
  4. If the sentence contains words such as "Initialize" or "Clean up," the module probably has temporal binding.
model new zone import 'GVol.f3grid' zone face skin zone group 'chuqiba' range group 'ZG_001' zone group 'jiyan' range group 'ZG_002' zone group 'ziba' range group 'ZG_003' zone group 'fenxisha' range group 'ZG_004' zone group 'fentu' range group 'ZG_005' zone group 'niantu' range group 'ZG_006' zone group 'fenxisha' range group 'ZG_007' zone group 'ZG_001' remove zone group 'ZG_002' remove zone group 'ZG_003' remove zone group 'ZG_004' remove zone group 'ZG_005' remove zone group 'ZG_006' remove zone group 'ZG_007' remove model configure fluid geometry import 'shui4.dxf' zone water density 1000 zone water set 'shui4' zone gridpoint fix velocity (0,0,0) range position-z -0.1 0.1 zone gridpoint fix velocity-x range position-x 1519.9 1520.1 zone gridpoint fix velocity-x range position-x -0.1 0.1 zone gridpoint fix velocity-y zone cmodel assign elastic zone property bulk 50e6 shear 18e6 density 1500 zone cmodel assign mohr-coulomb range group 'jiyan' zone property density 2500 bulk 2.778e10 shear 2.542e10 zone cmodel assign mohr-coulomb range group 'niantu' zone property density 1910 bulk 8.2353e7 shear 4.8276e7 cohesion 1.6e4 tension 0 friction 9.5 zone cmodel assign mohr-coulomb range group 'chuqiba' zone property density 2060 bulk 3.846e9 shear 2.222e9 cohesion 0 tension 0 friction 37 zone cmodel assign mohr-coulomb range group 'ziba' zone property density 2060 bulk 3.846e9 shear 2.222e9 cohesion 0 tension 0 friction 37 zone cmodel assign mohr-coulomb range group 'fenxisha' zone property density 2030 bulk 5.303e7 shear 2.734e7 cohesion 4e3 tension 0 friction 21 zone cmodel assign mohr-coulomb range group 'fentu' zone property density 2040 bulk 3.4375e7 shear 2.1154e7 cohesion 4e3 tension 0 friction 16.8 zone fluid cmodel assign isotropic zone fluid property permeability 6e-4 poros 0.6 range group 'chuqiba' zone fluid property permeability 1e-14 poros 0.2 range group 'jiyan' zone fluid property permeability 6e-4 poros 0.6 range group 'ziba' zone fluid property permeability 2.05e-10 poros 0.3 range group 'fenxisha' zone fluid property permeability 1.25e-10 poros 0.3 range group 'fentu' zone fluid property permeability 2e-13 poros 0.25 range group 'niantu' zone initialize fluid-density 1000 zone gridpoint initialize fluid-modulus 2e9 zone gridpoint initialize saturation 1.0 range position-y -10 0 zone gridpoint initialize saturation 0.0 range position-y 0 10 zone gridpoint initialize pore-pressure 0.0 gradient (0,0,-10e3) model gravity 0 0 -10.0 zone fluid active on zone mechanical active on model history name 'fluid' fluid time-total model history name 'mech' mechanical ratio model solve ratio 1e-4 fluid-time-total 1e6 model save 'coupling_result.sav' model factor-of-safety filename 'safety_factor' associated 报错*** Bad conversion of parameter number 5 (fluid-time-total). Expected tokens: Keywords: and clock convergence creep cycles cycles-total cycles-total-zone dynamic fish-call fish-halt fluid mechanical or ratio ratio-average ratio-flow ratio-local ratio-maximum thermal time time-total time-total-zone unbalanced-average unbalanced-maximum While processing line 71 of file C:/Users/杨彦/Desktop/LG/LG.txt.
最新发布
03-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值