This question already has an answer here:
I searched everywhere and I still can't figure out the difference between a Repository and a DAO.
Suppose we have a Product object, so for me the it would be like this :
class Product {
public int id;
public string name;
}
class ProductDAO {
public void add(Product p) {//saving the product}
public void delete(int id) {//deleting a product by id}
public Product update(Product p) {//updating a product}
public List<Product> listProducts() {//listing all products}
}
So in a real world project, every Entity should be in a 1-on-1 relation with a DAO class, and from what I've read, a Repository does the same job and can have the same methods I've added in the DAO above for example, except the update
method? I don't understand why, is this even true?
Could you please give me a very small example describing the difference ?
Thank you in advance.
Aucun commentaire:
Enregistrer un commentaire