我会尝试写一些关于软件耦合和内聚的想法,但我不确定它们是什么意思。因此,如果您想通过示例解释您的答案,请使用简单的代数表达式想象代数是一种顺序编程语言所以我们都能理解您在谈论的内容......
所以这就是我想要相信的(¿这是正确的吗?):
'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)
答案 0 :(得分:0)
有趣的观点,您正在理解更大的概念。既然你引用了维基百科的文章,你认为你的例子代表了列出的十种耦合类型中的任何一种吗?
我看到也许你的例子可能代表数据和/或消息耦合,但这是关于它的,因为基本的代数语句不保持状态(即商店值),例如。
首先要意识到这个简单的代数最终会过于简单化,无法代表软件开发中所有重要的耦合模式。我会立即建议在函数中添加多个变量,并使用不同的变量名等,以增加函数卷积的可能方式。
为了说明一些其他的耦合模式,你至少需要一些方法来存储值并引用先前存储的值...我们在解决代数问题时所做的事情,但是没有用通用语法或结构教授的东西。 (回想一下草稿纸和边缘的工作问题以解决问题吗?可能没有人教过你这么做的严格系统,也不是每个人都遵循的。)当你开始将这些功能添加到你的例子中时说明不同的耦合,你基本上会得到相当于你自己的编程语言。根据您的意图,这可能是一个非常值得和愉快的练习,但您也可能会发现尝试用现有语言表示耦合类型以更有效地学习概念。
答案 1 :(得分:0)
进一步阅读(感谢Cade Perkins),看起来我错了。
示例实际上是关于cohesion (according to wikipedia):
'Implementation of A with Low Cohesion
'(Random cohesion because there is )
' no reason 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 Another Random Cohesion
a(x) = 2x + 1
r(x) = a(x) + 3x + 2
...
'Implementation of A with Functional Cohesion
a(x, y) = x + y ' Groups Addition
b(x, y) = x * y ' Groups Multiplications
r(x) = a(b(5, x), 3)