How does the Repository Pattern Differ from a Simple Data Access Layer?

后端 未结 2 339
不思量自难忘°
不思量自难忘° 2021-01-30 22:57

I\'ve been confused by what I\'ve been reading during my research on the repository pattern. I\'m wondering if folks are (incorrectly?) using that word when they simply mean a d

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-31 00:02

    In general I agree with author's statements, but I'd like to add some details

    Difference between Repository and DAL/ORM that first not only abstracts the persistence mechanism, but also provides collection-like interface for accessing domain objects … and isolates domain objects from details of the database access code:

    Differences

    For external layers, such as Business Logic:

    • Helps to avoid leaky abstraction. External layers depend on abstraction of Repository, rather than a specific implementation of DAL/ORM. Thus you could avoid all infrastructure and logical dependencies while working with Repository.
    • operates with domain objects, rather then a instances of POJO/POCO/DTO
    • CRUD operations applied to collection-like interface provided by Repository, rather then specific DAL/ORM methods. For example .net: working with collection that implements IEnumerable, rather then entity-framework context or nhibernate session

    Similarities

    Repository contains DAL/ORM underneath and serves same purpose

提交回复
热议问题