The best functions have _____

high cohesion and tight coupling
high cohesion and loose coupling
low cohesion and tight coupling
low cohesion and loose coupling

The correct answer is: B. high cohesion and loose coupling.

Cohesion is a measure of how well the parts of a module belong together. A module with high cohesion has a single, well-defined purpose. A module with low cohesion has multiple, unrelated purposes.

Coupling is a measure of how strongly two modules depend on each other. A module with tight coupling is highly dependent on other modules. A module with loose coupling is loosely dependent on other modules.

In general, it is desirable for modules to have high cohesion and loose coupling. This makes the modules easier to understand, test, and maintain.

High cohesion means that each module has a single, well-defined purpose. This makes it easier to understand what the module does and how it works. It also makes it easier to test the module, because you can focus on testing that the module does what it is supposed to do. And it makes it easier to maintain the module, because you can change it without affecting other modules.

Loose coupling means that modules are not highly dependent on each other. This makes it easier to change one module without affecting other modules. It also makes it easier to reuse modules, because you can use them in different contexts without having to worry about how they interact with other modules.

However, there are some cases where it may be desirable for modules to have low cohesion or tight coupling. For example, if you are writing a library, you may want to make the modules as loosely coupled as possible so that they can be easily reused. But if you are writing a system that needs to be very efficient, you may want to make the modules as tightly coupled as possible so that they can communicate with each other quickly and easily.

In general, it is important to consider the trade-offs between cohesion and coupling when designing modules. The best approach will vary depending on the specific needs of the system.

Exit mobile version