Code Smell – Bad Smell in Code :: understand Long Classes
Understand Long Classes. Its like a Big BOM or Big Class.
In an effort to make our classes and methods small, we might create too many tiny classes and methods. So this rule suggests that we also keep our function and class counts low.
High class and method counts are sometimes the result of pointless dogmatism. Consider, for example, a coding standard that insists on creating an interface for each and every class. Or consider developers who insist that fields and behavior must always be separated into data classes and behavior classes. Such dogma should be resisted and a more pragmatic approach adopted.
Our goal is to keep our overall system small while we are also keeping our functions and classes small. Remember, however, that this rule is the lowest priority of the four rules of Simple Design. So, although it’s important to keep class and function count low, it’s more important to have tests, eliminate duplication, and express yourself.
When a class is having too many functionalities, think about breaking it up:
Extract Class helps if part of the behavior of the large class can be spun off into a separate component.
Extract Subclass helps if part of the behavior of the large class can be implemented in different ways or is used in rare cases.
Extract Interface helps if it’s necessary to have a list of the operations and behaviors that the client can use.