I understand the benefits of three tier architecture ( for example, changing code in one layer doesn’t usually affect code in other two layers ), but I don’t understand why it would be bad idea for UI layer to ( in certain circumstances ) directly access the `data layer.
a) I can think of few reasons why UI should only talk to BLL layer:
-
this way
UIdeveloper doesn’t need to know details ofDB schema, sinceBLL layerabstracts DB tables using custom objects. -
also, often times
BLL layerprocesses/validates the incoming data before passing it through to another layer
Are there any other reasons?
b) But if same developer is writing all three tiers, then are there really any reasons why UI layer shouldn’t directly access data layer (in cases where it doesn’t need the BLL layer to process/validate data)?
thank you
Some applications are small enough that a n-tiered architecture is overkill. When you start working with larger applications (remember small application tend to grow into big applications) then it becomes important to:
Most important is the ability to test your code without requiring a connection to a database thereby allowing you to truly isolate the object under test.
As for minimizing the impact of change, as your requirements change, your design will likely change. If logic and data access is scattered across your application, then small changes introduce significant risk (and additional testing effort).
Now if you’re a one man shop and don’t expect your software to grow in any significant way, then there’s little need to prepare for it with a more complex design.
On the other hand, they’re called “best practices” for a reason.