Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

Tight-coupling vs. loose-coupling

Abdul Monum

Coupling in software development refers to the degree of dependency between two modules/classes/objects in a software application.

For instance, classes are coupled when methods in one class use methods or instance variables defined in a different class.

As you can guess, tight-coupling is when there are many inter-dependencies between two modules. Alternatively, loose-coupling is when there are few inter-dependencies between two modules.

Ideally, we want loose-coupling, as we want to design modules so that all interdependencies are minimized and we have a clear separation of concerns among each module.

But how do we measure coupling?

In the realm of software development, connascence is a way of measuring the coupling in your code. Two modules are said to be connascent if changing one requires a change in the other to maintain the system’s overall correctness. Connascence has three qualities: Strength, Degree, and Locality. Let’s compare tight-coupling and loose-coupling in terms of these qualities.

Strength of connascence

If reducing the coupling between two entities requires an easy, simple change, connascence is said to be weak. If the change is complex and difficult to refactor, connascence is said to be strong.

Tight-coupling has strong connascence, whereas loose-coupling has weak connascence.

Degree of connascence

Connascence can occur to a small degree or a large degree. Two modules might be connected by multiple references, as opposed to a single reference. A connection of multiple references is said to have a high degree of connascence.

For instance, a given method might have many parameters that couple it to many external classes; this method has a high degree of connascence.

Tight-coupling has a large degree of connascence, whereas loose-coupling has a small degree of connascence.

Locality of connascence

Sometimes, coupling occurs close togetheri.e., you have two classes in the same unit that are interconnected, but sometimes that coupling occurs in two units that are very far apart. For example, you may make a change in the “lower left” part of your application, and it has an effect far away in the “upper right” of the program.

Tight-coupling has connascence that is far apart, whereas loose-coupling has connascence that is closer together.

RELATED TAGS

CONTRIBUTOR

Abdul Monum
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring