Data Access Object (DAO)

noun

say it: “DEE-ay-OH” /ˌdiː eɪ ˈoʊ/

A class that holds all the database code for one kind of data and returns models to the rest of the program.

What is Data Access Object (DAO)?

Data Access Object (DAO) — A class that holds all the database code for one kind of data, such as products. The rest of the program calls its methods and gets models back, so no other class needs to know any SQL.

class ProductDao
{
    public List<Product> GetAll() { /* SELECT ... FROM Products */ return []; }
    public Product? GetById(int id) { /* SELECT ... WHERE ProductID = @id */ return null; }
}

In a sentence

  • “The ProductDao is our DAO for products, so no other class contains SQL.”

Level: Journeyman · More OOP terms at this level

Updated