What type of module coupling is it when a function calls another function within itself?

161 Views Asked by At

When I have a function that calls another function within its body and stores the output of the other function in a an array for example and then uses it somehow.

What type of module coupling is this? I have looked through the types of coupling on Wikipedia https://en.wikipedia.org/wiki/Coupling_(computer_programming) and it seem like the most logical coupling is Data coupling. But I am not sure, since Data coupling is about passing outputs to the parameters of a function rather then that a function using the outputs of other functions within its body.

1

There are 1 best solutions below

0
ahoffer On

I do not see value in trying to classify every type of relationship as a form of coupling. Here is an example of what you have described.

int square(int num) {
  return num * num
}

make_squares() {
  size = 8
  int square_array[size]
  for (int i=0; i<size; i++) {
      square_array[i] = square(i)
  }
}

I have a function that calls another function within its body -- make_squares calls square.

I store the output of the other function in an array. The array is named square_array.

If I had to name the type of coupling, I would name it "dependency coupling" because make_squares depends on square. I consider those functions to be loosely coupled.