Sign in
Log inSign up
Which design pattern do you prefer, Active Record or Repository?

Which design pattern do you prefer, Active Record or Repository?

Jan Vladimir Mostert's photo
Jan Vladimir Mostert
·Mar 12, 2016

Active Record Pattern

64%

Repository Pattern

36%

25 votes · Closed

When using Object Relational Mapping, you typically have two options, using the Active Record Pattern or using the Repository Pattern.

Active Record Pattern:

Entity e = Entity.create();
e.setSomeField("abc");
e.save();

Repository Pattern:

Entity e = Entity.create();
e.setSomeField("abc");
repository.save(e);

Both have their pros and cons - active record, you have fewer classes, but you mix your business logic into your data model, repository, you have a lot more classes, but your data model is separate from your business logic.

Which do you choose and why?

For some pointers, see: