3 Basic data manipulation

 

Meditation and programming

This chapter covers

  • Representing records with string maps to improve flexibility
  • Manipulating data with generic functions
  • Accessing each piece of information via its information path
  • Gaining JSON serialization for free

After learning why and how to separate code from data in the previous chapter, let’s talk about data on its own. In contrast to traditional OOP, where system design tends to involve a rigid class hierarchy, DOP prescribes that we represent our data model as a flexible combination of maps and arrays (or lists), where we can access each piece of information via an information path. This chapter is a deep dive into the second principle of DOP.

Principle #2

Represent data entities with generic data structures.

We increase system flexibility when we represent records as string maps and not as objects instantiated from classes. This liberates data from the rigidity of a class-based system. Data becomes a first-class citizen powered by generic functions to add, remove, or rename fields.

►Note

We refer to maps that have strings as keys as string maps.

3.1 Designing a data model

3.2 Representing records as maps

3.3 Manipulating data with generic functions

3.4 Calculating search results

3.5 Handling records of different types

Summary