Search code examples
architecturebusiness-logic

Business layer in an asp.net application


Suppose you have a web application where based on some numbers the user has entered you give him another number (over simplified) when he/she clicks a button. All the data is stored in SQL server. Now I can get all the required data to the Business access layer and do the calculation there. Or do the calculation in the database stored proc and send the result to the application. I strongly prefer the latter,because I find it much easier. But some people may argue all the business logic must lie in business layer in the app. I feel if there is any business logic in the app, it belongs in business layer. But you don't have to have the data related business logic in the app.

What would the experts recommend?


Solution

  • If I might rephrase your question, I think you're asking, "Should I put my business logic in tsql or c#?"

    Personally, I would strongly recommend c# (or vb.net if that's what you're using). As a programming tool, it gives you so much more power than tsql. And when I say power, I mean power to write easy to understand, logical, well organized self documenting code, that, more importantly, is easy to maintain. Object oriented techniques like abstract classes and interfaces allow you to create not only reusable pieces of code, but allow you to enforce business logic that is easily traceable. This can be simulated with stored procs, but you end up jumping through hoops to implement it, and then trace it when there are issues.

    Code repositories are also built to integrate with VS much more easily than SQLserver, and change management, or even local dev environment upkeep becomes more difficult when things are centered on a database that is too large to run locally as opposed to updating a developers local working copy of c# code.

    Of course, in a single developer scenario, when no one else will ever work on this app, collaboration and change management considerations pale in comparison to the developer's comfort with tsql vs any other tool.

    And finally, just because c# provides rich language features, not everyone uses them. I can (and have!!) write a 1000 line c# method just as easily as I can write a 1000 line stored proc.

    Hope this helps, Lawrence