What are coupling and cohesion?

What are coupling and cohesion?
What are coupling and cohesion?
Coupling
- The degree of dependency between the component is called coupling.
- If the dependency is more then it is considered as tightly coupling and dependency are less then it is considered as loosely coupling.
Example Class A{
static int i=B.j
}Class B{ Static int j=C.k
}Class C{
static int k=D.m1();
}Class D{
public static int m1(){
return 10;
} - The above component are said to be tightly coupled with each other because dependency between component is more.
- Tightly coupling is not a good programming practice because it has several serious disadvantages.
- Without effective remaining component we can’t modify any component and hence enchantment becomes difficult.
- It suppresses reusability.
- It reduces maintainability of the application.
- Hence we have to maintain dependency between the component as less as possible i.e. Loosely coupling is good programming practice.
- The degree to which one class knows about another classâ€. If one class uses another class, that is coupling. Coupling is everywhere, but the level of coupling varies.
- Coupling refers to the degree to which one class knows about another, or makes use of another classes’ members.