-2

In which of the following lines of code coupling occurs? What is the kind of coupling? What is the problem induced by this coupling? How can the code be refactored to reduce coupling?

a busy cat

Community
  • 1
  • 1
user2013804
  • 29
  • 1
  • 4
  • You are likely to get a better response if you share your research and thoughts so far on this question, rather than expecting us to do your work for you. – DNA Apr 22 '14 at 10:48
  • And what if i have no idea how to solve the question? – user2013804 Apr 22 '14 at 11:06
  • What research have you done so far? Have you tried googling for "code coupling", for example, and read some of the resulting articles? What parts of them are you unclear on? If you show us that you have made some effort, we are more likely to be inclined to help. – DNA Apr 22 '14 at 11:42
  • So,I think that there is argument coupling, lines 9-13, since the opreration has a lot of arguments. Also, there is a routine coupling, lines 6-7 and 15-16. And maybe there is a control coupling, since the effect of performCleanup(.....) depend on the memFull and userRequest. – user2013804 Apr 22 '14 at 12:24
  • There should be four kinds of coupling the the code, but I can't find the last one. – user2013804 Apr 22 '14 at 12:46

1 Answers1

0

One way to approach this is to look at everything that the function/method depends upon.

It explicitly depends on its arguments - a form of control coupling, in this case.

However if we tried to compile this method in isolation, we can see all the other objects that it depends upon:

  • Log, and some specific methods of Log (note that we always seem to call both of these methods)
  • IGNORE_USER_REQUESTS
  • LOG_VERBOSITY_LEVEL, which is repeated 4 times in this method
  • A specific Collector class.
  • mem and 4 attributes (size, startAddress, etc) - probably a form of content coupling

I think you could argue that there are several cases of common coupling (shared global variables) there, though it's not terribly clear from the limited context. And the variables may be scoped within an object or package, not truly 'global'.

Then consider:

  • What would happen if we wanted to change one of these items. For example, if we wanted to use a different Collector implementation, or a different logger; or the structure of mem changed?
  • How would we test this method?

Note that we can't properly assess the impact of this coupling without understanding the wider code; if these objects are encapsulated within a single small class, for example, then the impact is less than if these objects are scattered throughout the entire code. Similarly, trying to refactor this code is a bit tricky in isolation, since we can only guess what we might be affecting elsewhere in our hypothetical code, and which objects we are free to refactor (some may be from 3rd party libraries, for example).

DNA
  • 42,007
  • 12
  • 107
  • 146