Class-level code smells are localized problems with the class in question. The kinds of problems that can plague a class are things like 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 actually be there, and they should be small. Only do in the class what needs to be done – 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 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...