Explain the advantages of modularity in program development.


Teaching Note:

Advantages include easier debugging and testing, speedier completion, etc.


Sample Question:


JSR Notes:


Firstly, note that "modularity" can be accomplished in OOP programming (primarily) through splitting your program into methods and classes (from which you make individual objects).

Easier Debugging & Testing - This is because you can isolate various parts of your code. So if you have an error when running your project, you can try running the code without using certain methods or instances of classes. And when you no longer have the error, you know that method or class that you eliminated from your testing is the one that either is the problem itself, or its interactions with other classes are causing the problem.

Consider the alternative - that you have all one big program, even not broken down into methods - in fact one that simply runs from line # 1 all the way to the bottom! How do you determine where your error is? You can't really eliminate lines here or there because they all depend on each other, nor could you do a "binary search" by commenting out the first half or the second half etc., because, again, all lines depend on each other.


Speedier Completion - This is mainly (I'd say) because it's easier to debug and track down problems.

But the other big advantage is that different modules (be they methods, or more likely classes) can be worked on by different team members at the same time.