There are several level of coupling between modules (according to this article):
According to the article:
Control Coupling: If the modules communicate by passing control information, then they are said to be control coupled. It can be bad if parameters indicate completely different behavior and good if parameters allow factoring and reuse of functionality. Example- sort function that takes comparison function as an argument.
Common Coupling: The modules have shared data such as global data structures. The changes in global data mean tracing back to all modules which access that data to evaluate the effect of the change.
We can actually pass for instance LogLevel
to an external logger. It can be treated as control information.
Can we consider that we have control coupling between our program and an external logger?
LogLevel
enum can also be treated as global data structure as well. Is it a common coupling?
Didn't get the main difference.
Depending on "LogLevel" contract (it is shared between all modules to indicate the level of log) is common coupling and sending "LogLevel" as a controlling parameter is control coupling.
There are two couplings but they are not crucial. Because your logger contract is not something that changes over time. If you are concerned about coupling with external libraries, you should consider defining your logger interface and implementing it with third-party logger adaptations.
A better approach would be to define different methods for every value of LogLevel. For example, your logger must implement Error, Debug, Info, and Warning methods. This way you get rid of control coupling.