开发者

Should Validation and Data Correction logic be done in business or data access layer?

So I have this general question of where should I have certain logic for example -

var data=GetItems();
if(data==null)
  //return some defaults
else
  return values

//second case..

 if(id<=0)
  //throw some exception
else
  return id

So should the above code should it be a part of data access layer (I think it should) or a par tof business layer. Also,validation of data should it generally b开发者_如何学JAVAe part of data access or business layer ?


I think the question is whether it should be between the business or the UI layer. The purpose of the data layer is to CRUD, so the logic should only be oriented towards that.

In the second example above, I'd say that's business logic. You're saying that a negative id has a meaning which should throw an exception. That meaning exists only within the logic of the application you're creating - there's nothing inherent to data storage that says that this should be the case.

So my vote is for business layer, and you should give some thought to the UI layer as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜