This chapter covers
- The benefits of separating code from data
- Designing a system where code and data are separate
- Implementing a system that respects the separation between code and data.
The first insight of Data Oriented Programming (DOP) is that we can decrease the complexity of our systems by separating code from data. Indeed, when code is separated from data, our systems are made of two main pieces that can be thought about separately: Data entities and Code modules.
This chapter is a deep dive in the first principle of Data-Oriented Programming:
Note
Principle #1: Separate code from data in a way that the code resides in functions whose behavior doesn’t depend on data that is somehow encapsulated in the function’s context.
The details of Principle #1 are summarized in 2.1.
We illustrate the separation between code and data in the context of the Library Management system that we introduced in chapter 1, and we unveil the benefits that this separation brings to the system:
- The system is simple: it is easy to understand
- The system is flexible and extensible: quite often it requires no design changes to adapt to changing requirements