Should a user model have all the actions that involve it?

5

When I search, I see that in MVC we should separate the models so that it becomes more organized and easier for an upcoming developer to understand the system.

I have the basic actions like login, registration, logout. Would it be correct, in the MVC pattern, to condense all these into a model User ? or should you separate the actions in their respective models?

    
asked by anonymous 18.10.2017 / 13:17

1 answer

3

This does not have to do with MVC, but with modularization or organization of the project with a whole independent of being MVC or not. It even has to do with object orientation.

Facilitating maintenance is somewhat subjective.

In general we can say that separating everything becomes easier to maintain, more cohesive and maintains the principle of sole responsibility.

On the other hand, the code gets bigger, needs more elements to unite all this together, and often maintenance will not benefit from all this separation.

It is curious that the orientation to the classical object says that everything referring to the object must be next to it. But what they do in practice is the opposite of this and separate everything that is not strictly necessary for that object.

No one can say what is best for your case, not least because it is not well defined. Without good definitions you can not decide anything. One of the biggest mistakes of developers is finding that code is more important than planning what you're doing by picking the requirements clearly and widely.

You need to analyze whether these things will work best for you if you are separated or together. What can you facilitate in the future? If you choose a path because someone said it should be so and it does not make sense for your case you are making a mistake. I do not even know what those separate parts would be.

No magic formula These decisions depend on experience. If you want the experience of others you need to give an adequate level of detail. Even this is complicated because each will decide from their experience that it may not work for another person.

Optimum solutions at the hands of those who do not know how to manipulate them becomes a bad solution. It is better to have a solution that is done right and the person to master its use.

That's why I always say that it's common for developers to adopt certain paradigms, patterns, architectures, even coding style that they do not understand why they're doing it and how to adopt it right, and it turns out to be worse. The tool you master is always better than the one you do not master.

    
18.10.2017 / 13:35