因此,在数据传输对象"中,应仅包含setter和getter.但是,如何处理还从数据传输对象中插入和删除对象呢?
So in the Data transfer Object there should be only setters and getters.. However what about handling also inserting and deleting objects from the Data transfer Object?
public class dto{ setters and getters... .. .. public void delete(){ CustomreDao.delete(this.ID); } }会违背DAO模式本身吗?
Would it be against the DAO pattern itself?
谢谢.
推荐答案问一下自己:更新DAO的delete方法有多困难?"如果您有很多DTO,并且突然需要更改DAO,那么您要做的就是很多工作.
Ask yourself this: "how hard would it be to update the DAO's delete method?" If you have a lot of DTOs and suddenly need to change the DAO, then that's a lot of work you just created for yourself.
将DTO连接到DAO的责任留在其他地方,您可以在此从单个点控制交互.
Leave the responsibility of connecting the DTO to the DAO to something else, where you could control the interaction from a single point.
更多推荐
DAO和数据传输对象
发布评论