Skip to content

What do low coupling and high cohesion mean? What does the principle of encapsulation mean?

February 23, 2009

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. 

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.

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

 

Principle of Encapsulation

Encapsulation is synonymous to information hiding. It is the process of concealing the internal representation and implementation of a class. Encapsulation shields the class from misuse and thus increases the resuability of the class. That is, it hides the implementation such that the internal structure of a class is free to change without affecting the implementation of the classes that use this particular class. 

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: