'Data Access Layer' is the same as 'Data Access Object'?

Asked

Viewed 2,309 times

3

I’ve always used DAO (Data Access Object) in Java Web and now I’m leaving for the platform. NET (C#), I saw that there is the DAL layer (Data Access Layer). I was confused, the DAL would be the same thing as the DAO? Because I saw some examples that used a DAL layer and inside it was created the model and etc.

  • Data Access Layer ?

  • yes, that’s the one...

  • War Lock, I made some changes to improve the title and make the question more objective, you can reverse if you think it necessary.

2 answers

4


Are different things.

DAL (Data Access Layer) - It is a project/layer responsible for the structure for access and persistence of application data. It is an architecture standard for separating the database access structure from the application presentation layer.

DAL has DAO objects (Data Access Object) which hide the complexity of data access logic. DAO is a design standard.

Example:

Imagine a database access scenario, where you have codes with the configuration/creation of your connection like this (below) scattered in your data presentation layer:

...

var conexao = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATASource=c:\Teste.mdb" );
conexao.Open();
comando = New OleDbCommand( "Insert INTO Teste ( Nome ) Values ( 'Xpto' )", conexao );
comando.ExecuteNonQuery();
conexao.Close();

...

This would lead to code replication, difficulty keeping the code spread across the application and any change in access to the data implies changing the entire application.

The idea of DAO is that this responsibility should be concentrated in a separate and independent layer of other layers.

The presentation layer shall not contain any reference to that data access code.

Create an interface for other layers to use data access methods.

Example:

public interface IClienteDAO<T>
{
   List<T> ExibirTodos(  );
   void Gravar(T obj);                                                        
   List<Cliente> Consultar(string nome);
}

Implementation of Iclientedao:

public class ClienteDAO : IClienteDAO<Cliente>
{    
   public List<Cliente> Consultar(string nome)
   {
       try 
       {
          using (SqlConnection con = ConexaoBD.GetInstancia.GetConnection()) {
          try 
          {
             con.Open();
             string sql = ("Select nome, idade from clientes where nome = '" + nome + "'");
             ...
          } 
          catch (SqlException ex) 
          {
              throw ex;
          } 
        ...
       }
    }

    //Demais métodos como ExibirTodos, Gravar...
}

References: DAO, DAL

  • I still did not understand the dal, what is the structure of the layers using Dal and Dao? gives an example

  • @Warlock to "roughly" would be this: http://i.stack.Imgur.com/Qf4bo.png

0

Well, as far as I know the definitions are correct:

DAL (Data Access Layer) and DAO (Data Access Object)

I believe the difference is that DAL is a definition for the database access layer and DAO is the object that performs this transaction.

For example, in visual studio, we can create class librarys, I think in java are equivalent to Packages, imagine that we will have a class library that will be our DAL (database access layer). So we have a client object that has some attributes. DAO (a class for example Cliente_dao), will be responsible for the persistence methods of these attributes in the database.

I hope I’ve contributed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.