Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Active Record and DAO?

Tags:

What's the difference between a Data Access Object and Active Record? They seem to be quite the same, as both built a layer between the application and persistence layer, and abstract away direct database access using SQL queries.

like image 992
helpermethod Avatar asked Jul 10 '11 11:07

helpermethod


People also ask

What does active record mean?

Active records are documents (both hardcopy and electronic) which are still actively being used by an office. They are usually referenced on a daily or monthly basis. Often times, if in paper, these records will be located in a handy place within the office since they are used frequently.

Is Dao same as repository?

DAO is an abstraction of data persistence. However, a repository is an abstraction of a collection of objects. DAO is a lower-level concept, closer to the storage systems. However, Repository is a higher-level concept, closer to the Domain objects.

What is DAO and ORM?

So, as already mentioned, DAO is a design pattern to minimize coupling between your application and you backend whereas ORM deals with how to map objects into an object-relational database (which reduces coupling between the database and you application, but in the end, without using a DAO your application would be ...

Is active record a good pattern?

Because of this, the active record pattern is best and most often employed in simple applications that are all forms-over-data with CRUD functionality, or only as one part of an architecture. Typically that part is data access and why several ORMs implement the active record pattern.


1 Answers

A Data Access Object (DAO) is an interface dedicated to the persistence of a model/domain object to a data-source. Here's a reference.

The ActiveRecord pattern works in a similar fashion, but puts the persistence methods on the model object itself, while the DAO defines a discrete interface.

The advantage of the DAO pattern is:

  • Its easy to define another style of persistence, eg moving from a Database to cloud, without changing the underlying impelementation, while the external interface remains the same, therefore not affecting other classes.

  • The persistence concerns are modularized away from the main model object concerns.

The advantage of the ActiveRecord pattern is simplicity.

like image 79
Jasper Blues Avatar answered Sep 19 '22 02:09

Jasper Blues