سؤال

I have a three tier architecture API to add and remove customers. Every customer has some employees that are responsible for that customer. Those employees are located in another collection of documents (I am using a NoSQL db) So if I am adding or updating a customer the customers gets a list of employeeIds that reference those employees. When a customer is now submitted, I have to check all those ids in a validation method:

function CheckIfAllEmployeeIdsHaveExistingEmployee(List<string> employeeIds) {...}

Would you do this in the DAL or in the BL? I am currently doing everything in the BL and only very simple CRUD operations and views are done in the DAL. But this logic was also a "database logic" in my SQL-times.

What do you think?

هل كانت مفيدة؟

المحلول

Checking if data provided for creating or updating an object complies to some rules or constraints is typically a BL layer responsibility. For this reason, checking if EmployeeId are valid should also be in the BL.

Putting it in the BLL gives you flexibility:

  • You can decide what to do if some Ids provided are valid and some are not (should you ignore the invalid ones? or should you return an error message?).
  • You could do the validity check of data when the UI needs it (instead of letting user enter wrong data and complain only at the end).
  • You could easily modify the rules, if one day you decide that the EmployeeId must correspond to an employee assigned to the geographic area of the customer.
  • You could change the DAL technology without having to reimplement your check.

On the other side, you could argue that this check could be done automatically using some referential integrity constraints in the DB that is checked during DAL operations only. This is a valid argument. But you have to accept the consequences, i.e. that the responsibilities between the layers are no longer so clear (part of the BL responsibility is delegated to the DB) and that you'll lose in flexibility.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى softwareengineering.stackexchange
scroll top