DDD “View Objects”?

后端 未结 4 692
情歌与酒
情歌与酒 2021-02-14 18:01

Given an application that involves, say, Companies, I might have a Company class. I will have a data access layer that populates a List . However, there will be

4条回答
  •  情深已故
    2021-02-14 18:40

    The approach you suggest can quickly increase the number of DAO:s you need to create and become a maintenance nightmare. The approach that several ORMs take is to proxy the data access, so your data access layer will return a list of interfaces, and the database call will be postponed until you invoke the data accessor, for instance

    list.getCompany(1).getName()

    . This is call lazy loading. You will still need to make a trade off between making many small or fewer big queries. This type of tasks is one of the strengths of ORMs, you can usually ask your ORM to prefetch parts of the object graph which you think will be used, and leave out other parts.

提交回复
热议问题