1

I'm gonna try to write some ideas ideas about software coupling and cohesion, but I'm not sure they mean anything practical at all. So if you want to explain your answers with examples please use simple algebraic expressions imagining that algebra is a sequential programming language so we all can understand what you´re talking about...

Read about it in wikipedia

So here is what I want to believe (is this correct?):

'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)
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
jacmkno
  • 1,189
  • 11
  • 25

3 Answers3

1

In very simple terms - Coupling indicates the number of connections a class has to other classes in your program. More it has, higher is the coupling. Ideally, the lesser the better.

vine_J
  • 123
  • 6
0

Interesting view and you are on the right path to understanding the larger concept. Since you referenced the Wikipedia article, do you think that your example represents any of the ten coupling types listed?

I see that perhaps your example could represent data and/or message coupling, but that's about it because basic algebra statements do not maintain state (i.e. store values), for example.

First realize this simple algebra will eventually be too simplistic to represent all important coupling patterns in software development. Right away I would suggest adding more than one variable to your functions and also using different variable names, etc. to increase the possible ways the functions can be convolved.

To illustrate some of the other coupling patterns, you at least need some way to store values and reference previously stored values... something we all do while solving algebra problems but something that is not taught with a universal syntax or structure. (Recall the scratch paper and working problems in the margins to get a problem done? Probably nobody taught you a strict system for doing this, nor one that everyone follows.) By the time you start adding these kind of features to your example just to illustrate different couplings, you'll essentially end up with an equivalent of your own programming language. Depending on what your intentions are, that might be a very worth-while and enjoyable exercise, but you also might find that trying to represent the coupling types with an existing language to be more efficient at learning the concepts.

C Perkins
  • 3,733
  • 4
  • 23
  • 37
0

Reading a little further (thanks to Cade Perkins), it looks like I was wrong.

The examples were actually about 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)
Community
  • 1
  • 1
jacmkno
  • 1,189
  • 11
  • 25