-
Notifications
You must be signed in to change notification settings - Fork 14
Home
Contents:
- Installation
- Configuration
- Mappers
- [Queries/CRUD](wiki/CRUD Operations)
In Principles of Enterprise Application Architecture by Martin Fowler, there are two common methods of object persistence: Active Record and Data Mapper. The Active Record pattern is the one most Rubyists are familiar with due to the gem of the same name.
I will not be contrasting all of the details of each pattern, but they differ primarily in one way. The AR pattern gives domain objects the ability to persist themselves whereas the DM pattern relies on third-party objects to persist them.
Perpetuity follows the Data Mapper pattern. This gives us the ability to serialize any object we choose into any data source we support. The only requirement is that we declare mappers for these objects.
The primary benefits are decreased coupling with the database and fast unit tests.
The ActiveRecord gem and some other Active Record-pattern implementations require not only a connection to a database in order to instantiate the objects, but in order to associate one object with another, the associated object needs to be persisted. This means unit tests are not possible unless you stub or mock all database interaction.