Search code examples
design-patternsactiverecordrepository-pattern

Is Repository pattern as same as Active Record pattern?


They seems to be similar.


Solution

  • They are different.

    Active Record Pattern defines An object that wraps a row in a database table or view, encapsulates the data access, and adds domain logic on that data.

    In the Repository pattern all of the data access is put in a separate class and is accessed via instance methods. To me, just doing this is beneficial, since data access is now encapsulated in a separate class, leaving the business object to get on with business. This should stop the unfortunate mixing of data access and business logic you tend to get with Active Record.

    Check this link for understanding:

    http://moleseyhill.com/blog/2009/07/13/active-record-verses-repository/