Questions tagged «datamapper»

5
数据映射器,表数据网关(网关),数据访问对象(DAO)和存储库模式之间有什么区别?
我试图提高自己的设计模式技能,并且很好奇这些模式之间的区别是什么?它们似乎都是同一个东西-封装特定实体的数据库逻辑,因此调用代码不了解基础持久层。根据我的简要研究,所有这些方法通常都会实现您的标准CRUD方法并抽象出特定于数据库的详细信息。 除了命名约定(例如,CustomerMapper与CustomerDAO,CustomerGateway与CustomerRepository)之外,还有什么区别(如果有)?如果存在差异,您何时会选择一个? 过去,我会编写类似于以下内容的代码(自然而然地简化了-我通常不会使用公共属性): public class Customer { public long ID; public string FirstName; public string LastName; public string CompanyName; } public interface ICustomerGateway { IList<Customer> GetAll(); Customer GetCustomerByID(long id); bool AddNewCustomer(Customer customer); bool UpdateCustomer(Customer customer); bool DeleteCustomer(long id); } 并具有一个CustomerGateway为所有方法实现特定数据库逻辑的类。有时,我不会使用接口,而是将CustomerGateway上的所有方法设为静态(我知道,这使得它的测试性较差),因此可以这样称呼它: Customer cust = CustomerGateway.GetCustomerByID(42); 对于数据映射器和存储库模式,这似乎是相同的原理。DAO模式(我认为与网关相同)是在鼓励特定于数据库的网关。 我想念什么吗?拥有3-4种不同的方法来做同样的事情似乎有些奇怪。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.