Software is a model of an aspect of the real world. The real world changes as we learn and grow, and we need to adapt our software to encompass these changes. In this way, as long as the software is being used, it is never finished. This also means connections in the real world must be represented in our code: the code is a codified structure from the real world.
In this chapter, we first discuss where different types of code structure come from. Then we examine three different ways behavior can be embedded in code and how to move behavior between these approaches. Having established the types of structure we are dealing with, we discuss refactoring: when it is helpful and when it may be disadvantageous. Finally, we look at different types of unexploited structures and how to use them with the refactoring patterns we have learned.
In software development, we deal with several types of structure (that is, recognizable patterns). Such a structure could be two similar methods or something people do every day. There is structure in the domain, structure in the program’s behavior, structure in our communication, and structure in the code.