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?
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 methodmem
and 4 attributes (size, startAddress, etc) - probably a form of content couplingI 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:
mem
changed?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).