In an MVC project, where should I leave the enums?

Asked

Viewed 576 times

2

I am developing a program with MVC standard, I needed to create some enum, and left them in the layer Model, but I was in doubt about its location, which would be the most correct layer to house the enum of a project?

  • 1

    It depends on what they serve, It can be in the model if they are important or are part of the model.

  • @bigown They are only used in the controllers, so the right one would put them in the Control layer ?

  • I gave an answer.

1 answer

7


Without knowing the exact problem, you can’t answer it. It is absurd for anyone to say where to put something without knowing the specific need. This is because of the cake recipe culture that has nothing to do with professional programming.

If the enumerations are part of the model, if they are part of the business rule that you are building, then the normal is to be in the model. Only those who are creating the app can say this.

If the enumerations help the controller function, then it’s probably where you should put it. This is usually done when it is part of the application rule.

There are cases that is not to put in either of the two and even fits an extra separation (helpers). You need to put an end to this idea that because the app has three tablets, it has the right place to put things. There’s a certain place, but it’s not a ready rule, you have to put it in the right place.

There is even consensus where the business rule should go, and many say it must go in the controller. So to claim that something goes somewhere without knowledge of the case is pure opinion without foundation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.