Wrap-Up

A Repository is a mechanism that acts as a storage location. The difference between a DAO and a Repository is that a DAO follows a database-first approach, decreasing cohesion with many low-level methods to query the database. Depending on the underlying persistence mechanics, we've seen different Repository approaches:

  • Collection-oriented Repositories tend to be purer to the Domain model, even if they persist Entities. From the client's point of view, a collection-oriented Repository looks like a collection (Set). There's no need for explicit persistence calls on Entity updates, as the Repository tracks changes on the objects. We explored how to use Doctrine as the underlying persistence mechanism for this type of Repository.
  • Persistence-oriented Repositories require explicit persistence calls, as they don't track object changes. We explored Redis and plain SQL implementations.

Along the way, we discovered Specifications as a pattern that helps us query the database without sacrificing flexibility and cohesion. We also studied how to manage transactions and how to test our services with simple and fast in-memory Repository implementations.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset