Correct use of OOP in a three-layered c# asp.net database application

273 Views Asked by At

I'm starting C# and would like to know if there is any problem in approach below:

enter image description here

Briefly, in the layers there would be instances similar to the following:

UI

var userBll = _userBll.SaveUser(dtoUser); 

BLL

// Validations and other business rules
return _userDal.SaveUser (dtoUser); // Request DAL

DAL

// Return the saved user to the database
return userDb;

Is there a problem with this kind of approach, in which the UserBll class would contain the "SaveUser" method? Would not it be correct to have a User class responsible for calling the Save method? Something like:

var user = new User();
user.SaveUser()

In this case would there be a redundancy between the User object class and the UserDTO data transport class?

Sorry if this may sound like a silly question, but it really confuses me.

1

There are 1 best solutions below

0
On

The DAL is merely an abstraction over the underlying data provider. The BLL doesn't know of what's going on, just knows it wants to save a user, given the validation is successful.

I therefore believe the approach containing _userDal.SaveUser (dtoUser) is more appropriate for such a thing. But in my own apps, I usually have another assembly for common/shared items. Something like your dtoUser. I don't like direct dependencies between UI and DAL in 3-layered apps.