0

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.

1 Answers1

0

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.

Mualle
  • 1
  • 1
  • That makes sense. Which brings up another question. Right now I have all models in it's own project in my overall solution. I also have another project just for framework/helper classes. I have no other external references in my EntityModel project. Would adding a reference to my helper project be considered acceptable? –  Jun 17 '16 at 14:50
  • It's acceptable, since your helper/ infrastructure layer deals with cross-cutting concerns. You are allowed to reference it in any tier of your app. – Mualle Jun 18 '16 at 17:38