Just a quick question about best practice in MVC development.
Let’s say that I’ve got two controllers (cont1, cont2), each of which uses a separate model, model1 & model2.
All files are complex; the models contain dozens of methods.
Say, I finished developing the first controller and I’m in the middle of work on the second one. I need to create a method in model2 which will be exactly the same as one of methods in model1. It’s only a tiny method, to get, for example, a list of categories of some sort.
What’s the best approach of work – should I duplicate the method and include it in my model2, or should I retrieve it from model1?
The reasonable thing to do would be to get it from model1, but I don’t know if that would affect the execution time, as it would have to load both models.
I would be grateful for some feedback
Loading a second model will not have a noticeable impact on execution time. This is probably the way to go.
Also, each model should encapsulate data logic for a specific ‘object’. You can think of each model almost like a database table. So you probably do not really want to have the same method in two different places – and if you do, you may want to consider creating a plugin.