Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top