N-tier question: Where do you do the variable casting?
Our UI exposes user input as strings. All of them, including dates and n开发者_运维知识库umbers, are coming as strings. The question is: is it better to convert these to the appropriate type (datetime, int, etc) in the UI (and then pass converted var to the BLL methods), or in the BLL itself?
Input validation and conversion should be done on the UI layer.
Not only is this so your business layer is dealing with typed data, but also so that you can easily throw UI error messages if they enter the wrong type or if the value is outside your range*.
*Some frameworks have their own validation logic for this sort of thing... ASP.NET being the first I can think of.
UI type conversion should be done in the UI layer, not the BL layer. This decouples the UI from the BL.
I prefer to do type casting in the UI and have the BLL expect the proper datatype.
精彩评论