Understanding when sub-module is needed

When should we consider creating sub-modules? There are several factors to consider:

  • First, we could consider the size of the application. Size is an abstract concept and can be measured in several ways, some of which are mentioned here:
    • Number of lines of code: This is the simplest measure to understand the size of an application. The more lines of code in the source files, the larger the application. This is analogous to the number of pages in a book. It takes more time for you to read and understand the content for a book that has more pages.
    • Number of functions: When there are too many functions in a single module, it is more difficult to understand and learn all those functions. When there are too many functions, the number of interactions between functions naturally increase, making the application more prone to messy spaghetti code.
    • Number of data types: Every data type represents a kind of an object. It is more difficult for a developer to comprehend all the functions operating on a large number of data types because the human brain cannot handle too many concepts at the same time.
  • The second thing we should consider is separation of concern. As we look into an application that comprises various components, we may logically think of them as separate things that can be managed independently. Humans are an excellent species that know how to work on items that are small and organized.
  • Lastly, we can consider the complexity of matter. Sometimes, you look at the source code and realize that the logic is difficult to grasp. Perhaps it's the domain knowledge. Or, it could be a complex algorithm. While the size of the application is not large, it may still make sense to split the code into separate files physically.

So far, we have not set any concrete threshold for any of the preceding factors. That is because the decision to call something large or complex is quite subjective. A common way to do that is to have a discussion among several software engineers and make a group decision. Doing that allows us to overcome the original developer bias, where the person already knows everything by heart, and therefore, the person would tend to believe that the application is not too large nor too complex.

Suppose that you are ready to take the plunge and split part of your code into sub-modules. The next challenge is to figure out how to do it properly. The work can be part art and part science. To formalize the process for splitting source code into sub-modules, we will first discuss the concept of coupling.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.86.155