我将尝试写一些关于软件耦合和凝聚力的想法,但我不确定它们是否意味着任何实际的东西。所以如果你想用例子来解释你的答案,请使用简单的代数表达式,想象代数是一种顺序编程语言,这样我们都可以理解你在说什么......
所以这就是我想要相信的(这是正确的吗?):
'Implementation of A with Low Cohesion
'(Coincidental cohesion because there is no
' good reason or need to group the functions
' in this way)
a(x) = 2x + 1
b(x) = 3x + 2
r(x) = a(x) + b(x)
...
'Implementation of A with High Cohesion (Almost Atomic)
r(x) = 5x + 3
...
'Implementation of A with Low Cohesion too
a(x) = 2x + 1
r(x) = a(x) + 3x + 2
...
'Implementations of A with Functional Cohesion
a(x, y) = x * y 'Groups multiplication
b(x, y) = x + y 'Groups addition
r(x) = b(a(5,x), 3)