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

3

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

    
asked by anonymous 30.01.2015 / 18:56

2 answers

4

They are different things.

DAL ( Data Access Layer ) - 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's presentation layer.

The DAL has Data Access Object (DAO) objects that 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) spread out 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 by the application, and any change in data access would mean changing the entire application.

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

The presentation layer should not contain any reference to this data access code.

An interface is created so that the other layers use data access methods.

Example:

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

IClienteDAO implementation:

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

    
30.01.2015 / 20:08
0

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

Data Access Layer (DAL) 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 eg Client_Dao) will be responsible for the persistence methods of these attributes in the database.

I hope I have contributed.

    
04.02.2015 / 00:40