1

I have recently been learning about Data Access Layers, Business Logic Layers and Presentation Layers, but I still have a few things that aren't quite clear.

I can use the DAL and BLL with the Presentation Layer to get or set information in a database.

But I also thought about asp control events, and how I should implement them.

Should I, for example, try to put a button click event into the BLL or should I just leave it in the aspx code behind file?

And if I should put them into the BLL how would I go about doing this?

I'm not sure how to make an event call a method which is in the BLL, so any advice would be greatly appreciated.

Lucas
  • 10,476
  • 7
  • 39
  • 40
  • I wish I could accept more than one answer. I chose Tom B's answer because it was the simplest for me to understand and gave me a nice guideline to use while I learn more about N-Tiered approaches. – Lucas Nov 27 '10 at 15:51
  • No problem. We're all saying basically the same thing, except Andrew gave a high level explanation of proper architecture, I added general example implementation using interfaces, and Tom gave more specific examples. All in all, whatever helps you understand best =) – bitxwise Nov 27 '10 at 17:29

3 Answers3

3

Given this architecture:

Presentation -> Business -> Data

Any layer should only know about and make assumptions about the layer to its immediate right. This means that the presentation layer can talk to the business layer and use it's API but it should never talk directly to the data layer. The business layer can use the data layer's API but it should never know about or make assumptions about the presentation layer that consumes it. And obviously the data layer should know nothing about any of the other layers.

If you follow this general principal you will find that your application will be simpler and easier to maintain.

To answer your question though, button click events belong in the presentation layer - putting a button click event into your business logic would blur the lines between the two layers and would create unnecessary coupling.

Andrew Hare
  • 344,730
  • 71
  • 640
  • 635
2

If the event has to do with the business model, then you should create a method in the BLL. If it's a UI type of event, handle it in the code behind. So, for example, if the user clicks a button to calculate the shipping, in the button's click event handler (code behind) call your BLL object's CalculateShipping() method. If, however, you have a button that changes the background color of the page (I couldn't think of a better example) then you would handle that completely in the code behind.

Tom B
  • 2,160
  • 2
  • 13
  • 15
1

Your ASPX code behind file (Presentation Layer) could either have a direct reference to your BLL (results in coupling) or you can use a more service oriented approach. This would involve creating interfaces referenced by your Presentation Layer and implemented by your Business Layer. During application initialization (i.e. in your Global.asax file), you can you connect the BLL to your Presentation Layer via dependency injection or some other approach.

bitxwise
  • 3,534
  • 2
  • 17
  • 22