A user model should have all the actions that involve it?

Asked

Viewed 98 times

5

Whenever I research I see that in MVC we should separate well the models so that it becomes more organized and easy for a next developer to understand the system.

I have basic actions like login, registration, logout. It would be correct, in the MVC standard, to condense all of these into one model User? or should separate the shares in their respective models?

  • Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site.

1 answer

3

This has nothing to do with MVC but modularization or project organization with a whole independent of being MVC or not. It’s even about object orientation.

Facilitating maintenance is somewhat subjective.

In general we can say that if separate everything becomes easier to maintain, it gets more cohesive and maintains the principle of single responsibility.

On the other hand the code gets bigger, it needs more elements to bring it all together, and often maintenance won’t benefit from all this separation.

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

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

You need to consider whether these things will work better 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 like this and it doesn’t make sense to your case you’re making a mistake. I don’t 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 by their own experience that may not work for another person.

Optimal solutions in the hands of those who do not know how to manipulate them becomes a bad solution. Then it is better a solution more or less that is made right and the person dominates its use.

That’s why I always say that it’s common for developers to want to adopt certain paradigms, patterns, architectures, even coding styles that they don’t understand why they’re doing it and how to adopt it right, and it ends up being worse. The tool you master is always better than the one you don’t. Avoid the hype.

  • I agree with his point of view, but in this case came this doubt because the system is simple, and so it comes to have more models and in that separate things more, became more logical for me, because it is easier to identify. However, I imagined the same taking larger proportions, so I would prefer a model to have all the actions that involve it, so as not to have an unnecessary excess of files. It’s more at this point that I want to get to, even when it’s good to abstract these ramifications, which in one way or another are linked to the User model, and I still don’t know if I’m going to take advantage of this separation. Understands?

  • 1

    Well, simple systems don’t need much to facilitate maintenance. These invented complex architectural patterns are for complex systems and will have a lot of maintenance.

  • Okay, so in that case, I think a class would be more appropriate in both cases. Taking advantage of your knowledge, you have some material to indicate that it involves these areas?

  • 1

    In general this involves a lot of study, a lot of practice, a lot of experimentation, a lot of debate. It doesn’t have a little manual. A lot of mistakes are made because people think they can read something and always do it that way. But if it is to do so as simple as possible, you have less chance of going wrong. The more complicated the system, the less chance.

Browser other questions tagged

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