Chapter 7: Breaking a Large Program into Objects In This Chapter Understanding object-oriented programming Clarifying encapsulation, polymorphism, and inheritance Explaining design patterns Using object-oriented languages Providing real-life programming examples Breaking a large program into multiple subprograms makes programming easier. Instead of trying to write a single, monolithic chunk of code, you just have to write small subprograms that work as building blocks that you can stack together to create a much larger program. Unfortunately, computer scientists found that just dividing a large program into multiple subprograms didn’t magically solve all the problems of creating software. Some of the most prominent problems of subprograms include ✦ Interconnectedness: Rather than act as independent entities, subprograms are often allowed to interfere with other parts of a program. Not only does this cause problems in tracking down problems (bugs), but it also prevents subprograms from being reused easily in other projects. Instead of easily sliding a subprogram out of a program like a building block, it’s more like ripping a plant out of the ground by its roots. ✦ Task-orientation: Subprograms focus on solving one specific task. Unfortunately, trying to understand how this one task fits into the overall design of a large program can be confusing, much like trying to understand how a car works by studying a single gear. As a result, subprograms make large programs hard to understand and modify. Not only do you not know how a subprogram works with the rest of the program, but you also don’t know how changing a subprogram might inadvertently affect other parts of the program. ✦ Reusability: Theoretically, you can yank out a subprogram and reuse it in another program. However, if you copy and later modify a subprogram, you now have two nearly identical copies of the same subprogram. If you find a problem in the original subprogram, you now have to find and fix that same problem in any copies you made of that subprogram — provided you can find them all in the first place.