8 Stubbing, generics, and coupling

 

This chapter covers

  • Creating the Booking repository class using test-driven development
  • Separation of concerns and coupling
  • Programming with generics
  • Unit testing with stubs

This chapter sees the continuation of our short-term mission to implement repositories for every entity in the database. If we look at the larger picture, we can remind ourselves why we implement these repositories in the first place: Aljen van der Meulen, the CEO of Flying Dutchman Airlines, wants us to bring their old codebase into the modern era. We received an OpenAPI specification to adhere to (the service needs to integrate with a flight search aggregator), and we settled on using the repository/service pattern in our new codebase. Figure 8.1 shows where we are in the scheme of the book.

Figure 8.1 In this chapter, we’ll implement the BookingRepository class. In chapters 6 and 7, we implemented the CustomerRepository class. That just leaves the AirportRepository and FlightRepository classes for the repository section of our codebase. We’ll implement those in the next chapter.

In chapters 6 and 7, we implemented the repository class for the Customer entity. This time around, we’ll focus on the Booking entity. After reading this chapter, I hope you are familiar with the following:

  • The Liskov substitution principle
  • Separation of concerns and coupling
  • How to use generics
  • How to write watertight input-validation code
  • Using optional parameters

And, of course, much more.

8.1 Implementing the Booking repository

8.2 Input validation, separation of concerns, and coupling

Exercises

8.3 Using object initializers

8.4 Unit testing with stubs

8.5 Programming with generics

8.6 Providing default arguments by using optional parameters