Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where to put the Business Logic, AppLayer o DataLayer?

After reading this post (business logic database or application layer) I still don't have the sufficient reasons to fight the "business logic in database" topic.

In my current work, there is a lot of db transaction (actually) and all that crappy code is hard to maintain, a lot of duplication in the stored procedures, so if you want change a value in a table for a bit, you will need to find all of those procedures and change them to what you want. Same happens if you need to change a little bit a table design.

All the current developers know SQL very well, but they still being not experts in any DATABASE as a engine(8 devs).

Currently we are planning to migrate the entire core to a new version (including database design). And I need some examples of:

  • Why Business Logic in Database is sometimes EVIL ?
  • How much and when Business Logic in Database is a good practice ?
  • Why Business Logic in Application Layer is better for an enterprise application. ?

App Language: Java
Database: Oracle11g
The application will have Services, served as HTTP pages and as WebServices.

like image 236
Garis M Suero Avatar asked Mar 02 '11 16:03

Garis M Suero


People also ask

Where do you put application business logic?

The business logic should be placed in the model, and we should be aiming for fat models and skinny controllers. As a start point, we should start from the controller logic. For example: on update, your controller should direct your code to the method/service that delivers your changes to the model.

Where should business logic be?

The very definition of the terms "front end" and "back end" comes from the separation of business logic (back end) from the user interface (front end). So yes, business logic should be in the back-end, whether that is a remote service or simply a different layer in the same application.

Should you put business logic in the database?

Two good reasons for putting the business logic in the database are: It secures your logic and data against additional applications that may access the database that don't implement similar logic.

Which layer contains the business logic and the business data?

The Business Logic Layer also known as BLL act as an intermediate between the Presentation Layer and the Data Access Layer (DAL). This layer handles the business logic, business rules as well as calculations.


2 Answers

Crappy code is indeed hard to maintain. That is the nature of crappy code - not where it is located. Moving to a "crappy code in the front end" solution is, well, not really a solution.

And if you think database structural changes won't affect business logic coded in the front end... ummm - logic dictates differently.

I think some things are well handled in the front end, and some things are better handled in the back end. And I think that a proper PL/SQL API design that operates at a business object level can mitigate structural change problems by isolating them from the other layers.

But if there is any thought to supporting other DBs, then this is also a problematic idea as not every DB supports the same constructs.

As to where business logic belongs - that may depend entirely on your application and, indeed, for performance reasons you may find it advantageous to have some aspects of it in multiple layers. That, of course, can cause maintenence issues but this all becomes part of the trade-offs neccessary to deliver a project or product.

But there sure ain't one strict universal answer.

like image 171
Michael Broughton Avatar answered Oct 06 '22 07:10

Michael Broughton


Have you read these AskTom threads?

  • Application design - logic in Database vs logic in Web (Application) server
  • Business Logic - PL/SQL Vs Java - Reg
  • J2EE and Oracle's stored procedures

They are good reading and full of great wisdom from Tom Kyte. The only trouble is they don't support the answer you appeat to want - they support the opposite view!

like image 37
Tony Andrews Avatar answered Oct 06 '22 07:10

Tony Andrews