Class-level code smells
Class-level code smells are localized problems with the class in question. The kinds of problems that can plague a class are things such as cyclomatic complexity and depth of inheritance, high coupling, and low cohesion. Your aim when writing a class is to keep it small and functional. The methods in the class should be there, and they should be small. Only do what needs to be done in the class – no more, no less. Work to remove class dependency and make your classes testable. Remove code that should be placed elsewhere to where it belongs. In this section, we’ll address class-level code smells and how to refactor them, starting with cyclomatic complexity.
Cyclomatic complexity
When a class has a large number of branches and loops, it has an increased cyclomatic complexity. Ideally, the code should have a cyclomatic complexity value of between 1 and 10. Such code is simple and without risks. Code with a cyclomatic complexity of 11-20...