Tuesday, November 6, 2007

Very Interesting Critique Of Active Record

(Active Record, the pattern, not ActiveRecord, the library.)

I am not against the use of Active Record. I just don’t want Active Record to be the organizing principle of the application. It makes a fine transport mechanism between the database and the application; but I don’t want the application knowing about Active Records. I want the application oriented around objects that expose behavior and hide data.

In practical terms, this basically means, use ActiveRecord, but don't necessarily assume that your models are going to be ActiveRecord objects. This is actually a really good point. I've found that using plain old Ruby objects in a Rails app often results in something significantly cleaner and easier to work with and maintain. It's kind of like the difference between objects and resources. Building your application around resources, using ActiveResource, can require you to make that distinction, and lead you to a cleaner structure as a result.

Definitely worth reading - thought-provoking and insightful.

Uncle Bob: Active Record vs. Objects