Subsecciones

Patterns Active Record y DataMapper

Active Record

In software engineering, the active record pattern is an architectural pattern found in software that stores its data in relational databases. It was named by Martin Fowler in his 2003 book Patterns of Enterprise Application Architecture.

The interface of an object conforming to this pattern would include functions such as

plus properties that correspond more or less directly to the columns in the underlying database table.

Active record is an approach to accessing data in a database.

Las gemas activerecord y DataMapper siguen el patrón Active Record.

DataMapper

Martin Fowler (Catalog of Patterns of Enterprise Application Architecture):

  1. Objects and relational databases have different mechanisms for structuring data.
  2. Many parts of an object, such as collections and inheritance, aren't present in relational databases.
  3. When you build an object model with a lot of business logic it's valuable to use these mechanisms to better organize the data and the behavior that goes with it.
  4. Doing so leads to variant schemas; that is, the object schema and the relational schema don't match up.
  5. You still need to transfer data between the two schemas, and this data transfer becomes a complexity in its own right.
  6. If the in-memory objects know about the relational database structure, changes in one tend to ripple to the other.
  7. The Data Mapper is a layer of software that separates the in-memory objects from the database.
  8. Its responsibility is to transfer data between the two and also to isolate them from each other
  9. With Data Mapper
    1. the in-memory objects needn't know even that there's a database present;
    2. they need no SQL interface code,
    3. and certainly no knowledge of the database schema.
  10. (The database schema is always ignorant of the objects that use it.)

The gem perpetuity implements the DataMapper pattern.

Casiano Rodríguez León
2015-01-25