What demonstrates good code quality?

Efficient, reliable, high availability (services), secure, maintainable, reusable, extensible.

Good code is easy to understand, use, and maintain. Variables, functions, classes, etc, should be named in an appropriate manner, enabling the next person after you to effectively reuse or modify them.

It should be well tested. The code should have high test coverage – this will help you write code that works thoroughly, and help avoid any regressions in code functionality once more work is done on it in the future.

The code should demonstrate low coupling and high cohesion. From stackoverflow:

Cohesion refers to what the class (or module) will do. Low cohesion would mean that the class does a great variety of actions and is not focused on what it should do. High cohesion would then mean that the class is focused on what it should be doing, i.e. only methods relating to the intention of the class.

Example of Low Cohesion:

| Staff           |
| checkEmail()    |
| sendEmail()     |
| emailValidate() |
| PrintLetter()   |

Example of High Cohesion:

| Staff                   |
| -salary                 |
| -emailAddr              |
| setSalary(newSalary)    |
| getSalary()             |
| setEmailAddr(newEmail)  |
| getEmailAddr()          |

As for coupling, it refers to how related are two classes / modules and how dependent they are on each other. Being low coupling would mean that changing something major in one class should not affect the other. High coupling would make your code difficult to make changes as well as to maintain it, as classes are coupled closely together, making a change could mean an entire system revamp.

All good software design will go for high cohesion and low coupling.


Source here.

Leave a Reply

Your email address will not be published. Required fields are marked *