Can I use Repository to do the BLL part?

Asked

Viewed 671 times

3

I was reading about Repository vs Dao and I saw the following sentence:

[...] The Repository standard aims to support the Domain model providing persistence. Unlike DAO, which is an object of application infrastructure and is part of the persistence layer, the Repository is part of the Domain model that is part of the business.

So, Repository can be used as a class for BLL ?

4 answers

4

Depends: If in your project you want your business layer (BLL) not to have references to data access technologies, data mapping, etc... of your project structure you can use this Pattern design. But the implementation of Repository will not necessarily stay within your business layer (BLL).

Repository isolates domain objects (business-related) from access code details and mapping those objects with the database. That is, it adds a layer of separation between the data and domain access layers.

This means that if you have a business layer (BLL) in your application, you can use this Pattern design to have a clear separation between your data access layers and your business layer.

Por que ter essa separação e cenário onde utilizei:

I worked a little with Domain Driven Design (DDD) and in that scenario if you put your Repository within your business layer, you may end up having references to technologies (example Nhibernate, Entity, etc.), which is not recommended (since business rules have no relation to the technologies used in the project, the idea here is you do not mix these two things) when DDD is used.

In that case then we insert a(s) Interface(s) do(s) repository(s) in the business layer, leaving the infrastructure layer to implement the repository interfaces, and this layer does refer to the technologies used for recovery, data persistence, etc.

2

The Repository not only can you stay in BLL(Business Logic Layer), as it is his place, he will serve basically as the intermediary of your application for your DAL (Data Access Layer) where his DAO.

Of course depending on the architecture, the size of the project, or the "I want it this way and that’s it", you can also nest the two under the same layer.

  • Then serial Classbll -> Classrepository -> Classdal. Repository would be an intermediary of DAL, Dal would have data access(Insert,delete, update,select) which would pass to Repository which could have other gets (getClienteBy algumacoisa) and BLL would do the validation itself and the business rule "to add order, link products with customer, blabala" That?

1

I have implemented business rules (BLL) within Repository classes (DAO). I didn’t see any problem with that, and it’s very practical.

When necessary, you can easily refactor the code, and extract this code to a BLL class.

0

You can abstract Repository in an extra layer in your application, and it’s not wrong to apply your business rules within it. It would be wrong if you were doing this directly at DAO

Browser other questions tagged

You are not signed in. Login or sign up in order to post.