1

In my n-tier architecture, I have a mapper layer to fill my responsecontext from the dataset/datatable comes from DBlayer. So DBlayer calls Mapperlayer to get the things done. But before filling responsecontext i need to do some validation. For this, shall i call businesslayer from mapperlayer? Or i should just pass what i get from DBlayer to businesslayer and ask the businesslayer to call mapperlayer.

Here, My business layer will use Business Entities to do thier own operation. Kindly help me on to sort of this design decision.

2
  • Go to the other questions you have made, select an answer that provided the solution to your problem and click the big CheckMark next to that answer.
    – CD Smith
    Jun 8, 2012 at 12:00
  • tiers and layers are not the same thing. Jun 8, 2012 at 13:02

1 Answer 1

3

Either one will "work", but I prefer not putting such things in a business object.

Having the business layer call the mapper layer creates a circular dependency between packages. The mapper layer already has to know about the business layer - that is the heart of its responsibility.

But why should the business layer know about the mapper? Mapping has nothing to do with business logic. The harm, of course, is that you can never test them independently if there's a two-way dependency.

I'd keep it as a one-way dependency. You can test the business objects independent from the mapping objects that way.

I'd also keep the mapper inside the persistence tier, not situated between persistence and model. Have your persistence layer return business objects, not ResultSets. Let it be package private if possible. My reasoning is the same - minimum knowledge means minimal coupling.

There are different levels of validation. I'd say that data should have been validated long before it gets into your database. There should be no need to validate, except for specific business rules, when you query the database. Those rules should be part of the business transaction in the service layer, not the persistence layer.

3
  • Ok so you are saying its better to call mapperobjects from DBlayer? Also I am passing rqstcontext(AddressSearchRequestContext) thru out all the BL,FacadeLayer and DataAccess Layers. Isnt this make tight coupling?
    – Al.
    Jun 8, 2012 at 12:13
  • I believe it does. I see no reason why such a thing needs to escape out of the persistence tier.
    – duffymo
    Jun 8, 2012 at 12:18
  • They would not be layers if there were not a one-way dependency. Jun 8, 2012 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.