16th Meeting (October): DataMapper vs ActiveRecord

Lucas: DataMapper oder ActiveRecord
Comparison between the DataMapper and the ActiveRecord pattern.
When choosing a persistence strategy, the first decision you need to make is where to place the responsibility for carrying out the mapping. You have two very different options: you can either make each entity class itself responsible for the mapping, or you can use a completely separate class to do the mapping to the database.
The first option is known as the Active Record pattern: an object that wraps a row in a database table or view, encapsulates the database access, and adds domain logic on that data. An Active Record approach puts persistence methods directly onto the entity object. In this case, the Address class would probably have methods like Save, Update, and Delete, as well as a static Load method that queries the database for an Address object.
Nice as the Active Record pattern may be, it is often valuable to have an object structure that varies from the database model. You may want to map multiple classes to the same database table. You might have a legacy database schema that doesn’t fit the shape of the objects that you would want to express in some business logic (a common occurrence for me on my last several projects).

 

Watch the video:


View the slides

This entry was posted in Talks. Bookmark the permalink.