0
23kviews
High cohesion & Low coupling.
1 Answer
1
1.1kviews

Low Coupling:-

Coupling refers to the relationship of a module with another module. A module is said to be highly coupled with another module if changes to it will result to changes to the other module. And a module is said to be loosely coupled if a module is independent of any other modules. This can be achieved by having a stable interface that effectively hides the implementation of another module.

Low coupling can be achieved by having less classes linking to one another. The best way to reduce coupling is by providing an API (interface). OOP languages like C#, Java, C++ offer quite a few mechanisms to offer low coupling like public classes, public methods, interfaces and other interaction points between different classes and modules.

One last bit on low coupling / zero coupling is: Zero coupled classes are not very usable and very low coupled applications are very difficult to maintain. So striking a balance is definitely an art.

enter image description here

Benefits of low coupling are:-

maintainability – changes are confined in a single module.

testability – modules involved in unit testing can be limited to a minimum.

readability – classes that need to be analyzed are kept at a minimum

High Cohesion:-

Cohesion refers to the measure of how strongly-related the functions of a module are. Low cohesion refers to modules that have different unrelated responsibilities. High cohesion refers to modules that have functions that are similar in many aspects.

At a high level, you would like to consider 2 or more systems to handshake their information to create a more valuable system.

Example: In an Investment bank, pricing a Foreign Exchange derivative product requires an input & with 3 other systems like Market data Service, Trade service and Quants system. This is a very complex process as output from Quants could very well be accepted as an input to Market data service for further calculations, thus eventually valuating a Foreign Exchange derivative (as in the below image).

enter image description here

Another design level example of High cohesion would be of N-Tier architecture. You would want a user interface technology that makes it easy to wire up the business logic and data access layer. Cohesion is all around. You only need to recognize it for what it is.

The benefits of high cohesion are:-

Readability – (closely) related functions are contained in a single module.

Maintainability – debugging tends to be contained in a single module.

Reusability – classes that have concentrated functionalities are not polluted with useless

functions.

Please log in to add an answer.