Repository Pattern vs DAL

后端 未结 12 2085
Happy的楠姐
Happy的楠姐 2020-12-02 04:05

Are they the same thing? Just finished to watch Rob Connery\'s Storefront tutorial and they seem to be similar techinques. I mean, when I implement a DAL object I have the G

相关标签:
12条回答
  • 2020-12-02 04:18

    One could argue that a "repository" is a specific class and a "DAL" is the entire layer consisting of the repositories, DTOs, utility classes, and anything else that is required.

    0 讨论(0)
  • 2020-12-02 04:22

    One large difference is that a DAO is a generic way to deal with persistence for any entity in your domain. A repository on the other hand only deals with aggregate roots.

    0 讨论(0)
  • 2020-12-02 04:24

    From what I understand they can mean basically the same thing - but the naming varies based on context.

    For example, you might have a Dal/Dao class that implements an IRepository interface.

    Dal/Dao is a data layer term; the higher tiers of your application think in terms of Repositories.

    0 讨论(0)
  • So in most of the (simple) cases DAO is an implementation of Repository?

    As far as I understand,it seems that DAO deals precisely with db access (CRUD - No selects though?!) while Repository allows you to abstract the whole data access,perhaps being a facade for multiple DAO (maybe different data sources).

    Am I on the right path?

    0 讨论(0)
  • 2020-12-02 04:30

    My personal opinion is that it is all about mapping, see: http://www.martinfowler.com/eaaCatalog/repository.html. So the output/input from the repository are domain objects, which on the DAL could be anything. For me that is an important addition/restriction, as you can add a repository implementation for a database/service/whatever with a different layout, and you have a clear place to concentrate on doing the mapping. If you were not to use that restriction and have the mapping elsewhere, then having different ways to represent data can impact the code in places it shouldn't be changing.

    0 讨论(0)
  • 2020-12-02 04:30

    Advantage of using repository pattern is to mock your data access layer, so that you can test your business layer code without calling DAL code. There are other big advantages but this seems to be very vital to me.

    0 讨论(0)
提交回复
热议问题