I'm working on an asp.net MVC application that implements the traditional Data/ Business/Presentation layered approach.
One of my entity models (representing a person) contains address/contact information including a field for "State". My data source (which I have little control over) provides state values in full-text (Ex: "California" vs "CA", "Florida" vs "FL", etc).
I created a static helper class that we intend to use to transform the full-text values to their abbreviations.
My question is, where should this helper class be referenced and where should the transformation take place?
I see the following options:
- Use an accessor in the model that references this static class and performs the transformation on get. Something along the lines of:
public string State { get { return StateConverter.Abbreviate(_state); } }
perform the conversion in the business layer whenever this entity model used
Perform the conversion in the presentation layer whenever this value is displayed
I like the simplicity of having this take place in the actual model (via get accessor), but this smells a tiny bit like business logic. The other options mean that I will have to convert this in many places (duplicating logic, traversing through people lists, etc).
Thanks.
It is okay to put it inside your model since it is just a computed field. Moreover your Abbreviate(...) method doesn't even depend on any data outside your model. Your right to put it there.