How to use bll, dal and model?

In my company, I have to use Bll, Dal and the model layer to create database applications.

At school, I learned that every data set should be an object of my model. therefore, I create the whole model of my database. I also learned that for each table (or model object), a DAO must be created in the DAL. So I do it.

Now I'm stuck in BLL classes. I can write a BLLclass for each DAO / ModelObject, or I can write a BLLclass that combines some (logical) DAOs ... Or I can only write one Bllclass that will manage everything. (this last one I'm sure this is the best way.)

What is the best practice to solve this Bll problem?

And the second question. If bll needs a tablecontent from another table that it is not responding to, what is the best way to get the content? Go ask about the responsible BLL or go directly to the DAO?

I have been struggling with these issues for the past 2 months, and I do not know how best to deal with this.

+4
source share
2 answers

You must start with what you need to do the work on the application.

For example: "I need a website for user login"

  • I need a controller that uses a model to verify an alias and pass
  • Then I need a bll object to execute the logic for checking the alias and passing
  • Then I need a dal object to access the database to retrieve user information

If you don’t start thinking like this (top to bottom aproach), then you are going to write a lot of code that will never be used.

Note: if dal is an orm mapping or not, this is anecdotal. Also, if the model uses bsl or bsl, use the model. IMHO.

+5
source

At school, I learned that every databasetable should be an object in my model.

So you have not studied object orientation? Inheritance? Matching multiple types of objects with a single table? Only a simple β€œstupid” each table is one object? There are more logical ways of matching objects. All with their different good and bad sides (i.e. you choose them depending on the circumstances, among which the number of fields in each object).

I also learned that for each table (or model object) there must be a DAO created in DAL.

Go to school, demand to return the money - they were idiots. The generated DAO is bad for a start. It turns out worse to have one per object. CONFIGURATION trumps CODE - a common DAO can handle x different objects, depending on the configuration. Lot less code to test and download. Here's how the correct framework does it (e.g. Hibernate / NHibernate). You can easily write a DAL that contains about half a dozen methods that it provides during operations and processes an unlimited number of objects. At the beginning, you tell each DAL what object it should be processed with, and how so that it can generate the correct SQL, etc.

What is the best practice for handling this Bll 'problem?

Back to school, the basics of learning. Reading on O / R cards. Hibernate / NHibernate (you do not name the langauge you use), Toplink, etc.

If the bll needs a tablecontent from another table, where is the person in charge, what is the best way to get the content? Please ask the responsible BLL or go directly to the DAO?

Depends on the architecture. In general, a business object will be created from a factory, and it should only talk to the factory. Then the factory will deal with DAL - after and before that, do really interesting things, such as caching.

Read at Hibernate / NHibernate.

A good book is also the "old" Scott Ambler Building Works app, which works.

-5
source

Source: https://habr.com/ru/post/1303100/


All Articles