Coupling and Cohesion in 2 mins

Coupling

Coupling refers to how related or dependent two classes/modules are toward each other.

For low coupled classes, changing something one class should not really affect the other. High coupling between classes makes it difficult to change and maintain your code since classes are closely knit together. Making even small changes could become costly and risky.

Example

An example of high coupling may be an object class that contains references to a mysql database class and its functions. Changing databases to a postgres database will be more complex change as this class and likely others are coupled to mysql. The object class should not really care what datastore implementation is being used.

A low coupling implementation of the above would have abstract classes and interfaces decoupling the object and the data store so modifications to these separate things would likely be less complex

Cohesion

Cohesion refers to how focused the class is on what it does. Low cohesive classes have a wide variety of responsibilities and actions.

High cohesive classes only focus on what it should be doing, and contain only methods relating to the intention of the class.

Example of Low Cohesion:

The class below has a wide variety of functions

Employee class
checkEmail()
sendEmail()
emailValidate()
onboard()*

Example of High Cohesion:

The below class is much more focused on just the employee object.

Employee class
-name
-emailAddr 
setSalary(newSalary)
getSalary()
setEmailAddr(newEmail)
getEmailAddr()

Summary

Good software design has high cohesion and low coupling.

The most effective method of decreasing coupling and increasing cohesion is design by interface