chapter seven

7 Data validation at system boundaries (A solemn gift)

 

7.1 Introduction

At first sight, it may seem that embracing Data-Oriented programming means accessing data without validating it, in kind of a wishful thinking that data is always valid.

In fact, it is possible and even recommended to validate data when we follow Data-Oriented principles. This chapter illustrates how to validate data when data is represented with generic data structures. This chapter focuses on data validation that occurs at the boundaries of the system while in Part 3, we will deal with validating data as it flows through the system.

This chapter covers:

  • The strategic location of data validation
  • The JSON schema language
  • How to integrate data validation in an existing code base
  • Detailed information about data validation failures

7.2 Data validation in DOP

Theo has rescheduled his meetings, still not sure he has not made a big mistake to give DOP a second chance.

JOE: What is the aspect of Object-Oriented programming that you think you will miss the most in your big project?

THEO: Data validation.

JOE: Could you elaborate a bit?

THEO: In OOP, I had this strong guaranty that when a class is instantiated, its member fields have the proper names and proper types. While with DOP, it’s so easy to have small mistakes in field names and field types.

JOE: Well, I have good news for you. There is a way to validate data in DOP.

7.3 JSON schema in a nutshell

7.4 Schema flexibility and strictness

7.5 Schema composition

7.6 Details about data validation failures

7.7 Wrapping up