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
Data Access Layer ?
– gmsantos
yes, that’s the one...
– War Lock
War Lock, I made some changes to improve the title and make the question more objective, you can reverse if you think it necessary.
– Renan Gomes