Westicle
Westicle

Reputation: 87

Validation in BLL

I read somewhere that I should be performing validation in my BLL as well as UI. Is this the case and how should I handle errors/exceptions?

I'm creating an app to manage our client data. The users are able to delete a client if that client has no projects attached to it. The sub in the BLL is as follows:

Public Shared Sub DeleteClient(ByVal clientsID As Integer)

        Dim clientDataAccessLayer As New ClientDAO
        clientDataAccessLayer.DeleteClient(clientsID)

End Sub

I'm already checking on the UI and not calling this sub if the client has any projects but should I also add some validation within this sub and how should I do it? Throw an exception or simply not allow it to run?

Upvotes: 0

Views: 510

Answers (2)

iandayman
iandayman

Reputation: 4467

yes. you should add some validation within this sub (bll) and throw an exception which your UI should handle.

It may seem like breaking the DRY principle (because you are repeating logic to stop the option on the UI) but the business layer should always maintain data integrity. If for example you introduce different UI's or web services to your application the data integrity remains intact.

Upvotes: 1

Pankaj
Pankaj

Reputation: 10115

I read somewhere that I should be performing validation in my BLL as well as UI. Is this the case and how should I handle errors/exceptions?

Your exception hamdling should be done in Presentation layer only. Reason - Suppose you have Presentatin/DAL/BLL. Upon implementing the exception handling everywhere will cause performance issues. While, on the other hand implementing exception handling it in Presentation layer will cause the exception to come automatically in the catch block of your calling function

Validation should be in BLL only in case of validation check on database result.

Upvotes: 0

Related Questions