0

I'm creating a project and I'm having difficulty and contrasting opinions on how to do things when it comes down to separating layers. I'm not fully sure what layers should reference each other.

I have read in certain blogs/posts that the flow should be

  • the view references the business layer
  • the business layer references the data layer
  • the data layer only knows about it self

On the other hand I have also seen the following

  • the view references the business layer
  • the business layer knows only about itself
  • the data layer references the business layer

Using the second method I have been using the business layer using IOC but im reluctant to progress without more knowledge.

I have read a number of posts but the answers seem many and varied. Any clarification would be great.

Thanks

  • I understand the reasons that I should do it but I don't believe the above post answers my question. In some points it mentions a top down system. Does that mean the following is correct? -the view references the business layer -the business layer references the data layer -the data layer only knows about it self – Jamlow Sep 8 '14 at 11:13
  • thanks gnat but I don't believe this is a duplicate question – Jamlow Sep 8 '14 at 12:11
  • have you read the explanation referred in prior comment? in particular, sections 2. You discover that duplicate only looks similar... and 3. You discover that "duplicate" is totally different...? – gnat Sep 8 '14 at 12:13
  • There is another question that is similar meta.stackexchange.com/a/194495/165773 however this doesn't detail what layers should see and use each other. It seems to cover a more broad question - Why should i use layers – Jamlow Sep 8 '14 at 12:21
1

From further reading on stack overflow I believe I have found my answer. You do not want your business layer to access you data layer but rather have it injected using an IOC container. Using this method will also allow me to inject testable objects which will help unit testing.

This is exactly what I needed. Thanks for your help

1

In general, it doesn't matter. I wouldn't call the second version a "layered" architecture since the layers don't stack in the right order. It is also unclear in that approach who "glues" the view and the data layer so they work together.

The key thing though is that the relationships are non-cyclic, and unidirectional. This loose coupling allows you to replace those dependencies (IOC or not) should the need arise.

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