2017-03-31 59 views
0

我要试着写一些关于软件耦合和内聚的想法,但我不确定它们是否意味着任何实际的东西。所以,如果你想用例子来解释你的答案,请使用简单的代数表达式想象代数是一个连续的编程语言所以我们都可以理解you're谈论...¿关于耦合的意义是否正确?

Read about it in wikipedia

所以在这里是我想相信(¿这是正确的?):

'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

再读一点(感谢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)