David Wheeler: Any problem in computer science can be solved by another layer of indirection.
I increasingly find this to be very true. Why?
My personal understanding is:
- The code written initially solves a specific problem, so it is only for that specific case.
- Over time, the types of specific cases increase. If the original code is modified, it becomes more and more complex and difficult to change.
- In order to narrow down the problem, we abstract the bottom layer (the code that originally solved the specific problem), expose interface definitions, and let the upper layer adapt. The upper layer adaptation is to adapt different types of specific problems to the lower layer interface, which is equivalent to adding another layer.
- What are the benefits of step 3? The changes to the bottom layer code are minimal, and the upper layer only needs to adapt, which provides code isolation and reduces mutual influence. If there are issues with the adaptation at this layer, as mentioned in step 2, then continue to step 3, adding another layer. This way, one problem after another is solved layer by layer.
- Reality is quite similar to this logic. Initially, the code is rigid, and the more it is changed, the harder it becomes to change. So, parameters and configurations are extracted to allow for more flexible configurations.
Just a little insight, but it does make sense.