Active record pattern
Appearance
Active Record is a design pattern frequently found in enterprise applications.
Active Record takes the obvious approach to taking the data from database. A row in a database table or view is wrapped into a class. When object is created, a new row will be added to database when it's saved. When an object is loaded, it gets its information from the database, when it's updated, the row in the database gets updated. The wrapper class implements getters and setters for each column in the table or view.
One of the widely-used implementations is the Active Record implementation found in Ruby on Rails. For example,
a = Part.new a.name = "Sample part" a.price = 123.45 a.save
will create a new row in the database, and
a = Part.find(:first, :conditions => ['name = ?', widgetname])
will find the appropriate item from the database.
External links
- Short description from Patterns of Enterprise Application Architecture by Martin Fowler
- Ruby ActiveRecord documentation