Active Record To Repository

time to read 1 min | 137 words

David Hayden has a post about moving away from the Active Record pattern. In it, he suggests to create two classes per domain model object. For instnace, a Customer class and a CustomerDAO (data access object) class. I tend to call this object a Repository, instead of DAO, but this is mainly a matter of taste, I think.

What is more interesting is the different reasons for choosing one approach or the other.

I tend to use Active Record (both library and pattern :-) ) when I don't need to take complex actions along the persistance path. And use explicit Repository when I need to take actions along the persistance path (for example, filterring objects by security, turning deletes to logical deletes, turning updates to inserts, etc...).