Conversions can be done in the first layer ( UI ) ?
-
2Conversion *can* take place anywhere. The question is wheter it *should*, and that entirely depends on what your application is doing, and how. You will need to provide some more information to get any useful answers. – Fredrik Mörk Dec 15 '10 at 10:00
-
possible duplicate of [Convert string to image in 3-tier](http://stackoverflow.com/questions/4447438/convert-string-to-image-in-3-tier) – dtb Dec 15 '10 at 10:02
-
never to convertion in the UI that is bad practice – CoffeeCode Dec 15 '10 at 10:05
-
@CoffeeCode : Why? Where the conversion is done – ehsan_d18 Dec 15 '10 at 10:57
-
@ Fredrik Mörk : Each layer can be converted? Even ِDAL(DataAccessLayer). – ehsan_d18 Dec 15 '10 at 10:59
-
do the convertion on the model level. convetions must be done in the backend not frontend – CoffeeCode Dec 16 '10 at 10:20
2 Answers
For these kind of operations I personally create a Utils class/namespace
under project namespace
(myProjectNamespace.Utils
). A ststic
class with public static
members for conversions, formatting, calculations...
Put this class in BLL
(Business Logic Layer) most of the time but sometimes you need different Utils
for different layers.
-
BLL is not for validation. It's a good place for putting Logic. Most of the time `Utils` best place is there in compare to `UI` or `DAL` – Dec 15 '10 at 18:17
Assuming an image is an input - inputs usually come into a system through:
- The frontend interface / UI.
- A backend interface (service).
- An API call.
If the input is specific to - say the UI - then that would suggest it was a UI specific thing and should sit there.
The same rule / principle applies for the other input 'channels'.
if the API being called is in the BL then that's where it might sit.
Where Yousefvand is coming from (and which I agree with) is that if more than one component is using it then it's probably be a good candidate for putting in some osrt of reusable library.
So...
Conversions can be done in the first layer ( UI ) ?
Yes if the what you're converting is specific to the UI / UI technology being used; otherwise you could but probably shouldn't - in this case you'd probably be better implementing your converter in a utility.

- 9,880
- 3
- 33
- 59