Why do we need coding principles?

Isuru Sahan Kumarasingha
2 min readFeb 26, 2022

Coding principles are effect directly to software developers for many reasons.

Before jumping into the topic,

We should need to understand what is Cohesion and Coupling.

Cohesion

Basically, it is divided into two parts.

● High cohesion:- the class is focused on what should need to do(all the methods related to the class)

● Low cohesion:- the class is not focused on what should need to do(the methods not related to the class)

Coupling

Basically, in coupling refers to dependency between two classes/modules. It is also divided into two parts.

● High coupling:- it would make it difficult to change something without affecting another class

● Low coupling:- It would be no difficult to make changes without affecting another class.

So, what would be good software?

☆ it needs to be Low coupling and High cohesion

S.O.L.I.D are 5 object-oriented principles that will help you to understand the importance of principles.

Single responsibility

Open-close

Liskov substitution

Interface segregation

Dependency inversion

Single responsibility

As the title indicates, this rule says that each class should have a single task and a single goal. It means that a class will only do one duty, implying that it should have one cause to change.

Open-close

As the title indicates, this rule says that objects or entities should be open for extension, but closed for modification.

Liskov substitution

According to this principle, Every subclass/derived class should be able to substitute their parent/base class.

Interface segregation

The purpose of this principle, keep only using methods in application interfaces by separating application interfaces into smaller ones.

Dependency inversion

This principle says that Higher level modules should not depend on lower-level modules, but they should depend on abstractions.

Conclusion

These coding principles result in efficient, clean code that is simple to comprehend and test. As a result, the program is less expensive to maintain and easily expandable.

--

--