Definition of coupling using javascript example

When we talking about coupling, it is an important concept in software development. Coupling should be less when we developing software. It says the degree of the interaction between two or more modules should be less. According to that, we can easily handle our software development or maintenance without any effect on other modules badly. Example javascript code segment as below…

The above code has two functions. One is to set time out as 1 second to set the value as 10 and print the value. The other one is to call the 1st function. Assume that if you want to set the value as multiplying by 2 to after 1 second in the second function, we have to change also the 1st function. Because of that, it will high coupling. The solution as below…

According to the above code, it will pass a function as a parameter. The 1st function used the callback method which is not a keyword is also the method to accept parameters. studying that you can understand if we want to change something after 1 second we have to change only second module. Do not want to change the first module. Because of that, the degrees of interaction between the modules are very low. So that we can be called it low coupling. That's why I mention at the top of the post If we are going to develop software we need to maintain it as law coupling. It is not a rule, but if we follow up that we can easily manage the software development and software maintenance.

I am an undergraduate student of SLIIT following BSc.(HonS ) in IT specialization in Software Engineering