Question on dependency of Business Layer with Data Access Layer
-
I was reading the Enterprise solution patterns using Microsoft.net. I have a question while reading on Three Layered application, so just think of sharing with any of you and confirm. It is said that "Make sure you eliminate the dependencies between data access components and business layer components. Either eliminate dependencies between the business layer and the presentation layer or manage the dependencies here using the Observer pattern". My question is how can the business layer be independent from data access layer? Why because, for anything to be processed in business layer, the data needs to come from data layer. For eg: If I need to calculare employee PF, I should get the employee details from db, which is in data access layer. So there will be a function in businesslayer, which calls the corresponding function in data access layer. Is this not dependent or am I thinking stupidly? Or what exactly means that business layer should be independent from data access layer? Same as the case with business layer and presentation layer. There will be some business logic implemented with the business layer class. So inorer to perform that, we are calling that function on the happening of some events in presentation layer. I did not understand what exactly meant by this independent? Am I thinking wrong?
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
-
I was reading the Enterprise solution patterns using Microsoft.net. I have a question while reading on Three Layered application, so just think of sharing with any of you and confirm. It is said that "Make sure you eliminate the dependencies between data access components and business layer components. Either eliminate dependencies between the business layer and the presentation layer or manage the dependencies here using the Observer pattern". My question is how can the business layer be independent from data access layer? Why because, for anything to be processed in business layer, the data needs to come from data layer. For eg: If I need to calculare employee PF, I should get the employee details from db, which is in data access layer. So there will be a function in businesslayer, which calls the corresponding function in data access layer. Is this not dependent or am I thinking stupidly? Or what exactly means that business layer should be independent from data access layer? Same as the case with business layer and presentation layer. There will be some business logic implemented with the business layer class. So inorer to perform that, we are calling that function on the happening of some events in presentation layer. I did not understand what exactly meant by this independent? Am I thinking wrong?
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
The simplest way to think of it is "I don't care how you do it... Just do it!" You go to the grocery store, pick out a few things, and go to the register to pay for it. The cashier hits some buttons on the register, tells you how much it costs, takes your money, and gives you change. Now, you don't know how to work the register (Or maybe you do, if you've had a job like that, but the point is that you don't have to)... You just know that somehow the cashier is adding everything up and figuring out how much you owe. On the same note, the cashier doesn't know how the register works inside. He/she just knows how to push the buttons, scan the items, and get the right total. Maybe there's a system inside where it's notifying the stock room that product X needs to be resupplied. Maybe it's building up a database of how often each product is purchased... All the cashier knows is that they push the buttons and get the response they need. "Layers" in software are much the same way... The point is that all each layer knows is how to get what it needs from the layer below it. The presentation layer has no idea where all those employee details are coming from... It just knows how to take that data and make it look pretty on the screen. The business layer doesn't know how the data is being stored, or what the tables and fields are called... It just knows how to say "Give me all the details for employee 12345." So the short answer is that each layer is dependent on the other one doing its job, but not dependent on how that job is done. Like I said above, each layer looks to the one beneath it and says, "I don't care how you do it... Just do it!"
Proud to have finally moved to the A-Ark. Which one are you in? Developer, Author (Guardians of Xen)
-
I was reading the Enterprise solution patterns using Microsoft.net. I have a question while reading on Three Layered application, so just think of sharing with any of you and confirm. It is said that "Make sure you eliminate the dependencies between data access components and business layer components. Either eliminate dependencies between the business layer and the presentation layer or manage the dependencies here using the Observer pattern". My question is how can the business layer be independent from data access layer? Why because, for anything to be processed in business layer, the data needs to come from data layer. For eg: If I need to calculare employee PF, I should get the employee details from db, which is in data access layer. So there will be a function in businesslayer, which calls the corresponding function in data access layer. Is this not dependent or am I thinking stupidly? Or what exactly means that business layer should be independent from data access layer? Same as the case with business layer and presentation layer. There will be some business logic implemented with the business layer class. So inorer to perform that, we are calling that function on the happening of some events in presentation layer. I did not understand what exactly meant by this independent? Am I thinking wrong?
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
Assume there's a rule: nobody may have a salary higher then the CEO. Where to put this rule in the system? When you try to answer this question you will see that each choice (put it in the presentation layer, bussiness layer, data layer) has it advantages and disadvantages. Now repeat the question for the rule 'every order must have at least one line'. Would you put it in the same layer as the previous rule? Why or why not? I hope that you will see that there are categories of rules: some are better in the data layer, some better in the bussiness layer,... This is what MS is talking about... Rozis
-
Assume there's a rule: nobody may have a salary higher then the CEO. Where to put this rule in the system? When you try to answer this question you will see that each choice (put it in the presentation layer, bussiness layer, data layer) has it advantages and disadvantages. Now repeat the question for the rule 'every order must have at least one line'. Would you put it in the same layer as the previous rule? Why or why not? I hope that you will see that there are categories of rules: some are better in the data layer, some better in the bussiness layer,... This is what MS is talking about... Rozis
Apart from not knowing exactly how a lower layer does something, "removing dependency" could also be considered as "not knowing WHO is doing what I need to do", and that is acomplished using Interfaces. So you go from not only not knowing how, but neither knowing which class is the one that implemented the interface and is executing whatever you need from the lower layer. Why would you do something like this for a DAL? Two main reasons, first not to depend 100% on an implementation for a specific database engine (ie SQL Server), but to have an interface that could be implemented for different storage mechanisms; and second for testing purpose! Imagine you could automate your tests by implementing a piece of your DAL (interface) from a dummy class (either mock or stub) just to test your upper layers (probably business).