MVC: Lots of small models or a couple of big models?
I am in the process of writing and organizing my unfinished application in codeigniter and I am just wondering weather it is better to have lots of small models, 开发者_运维技巧so your only loading what you need when you need it; or making a couple of big models so it just loads all functions even though you only need one of them?
Any help would be appreciated. Thanks.
From a performance point of view it is better to only have a couple of big models(files). I believe that is one of the main reasons why Cakephp used(not keeping track of it) to be very slow. Just have a look at the dependencies Cakephp had.
But from a design point of view it is better to have a lot of small models because of the SOLID principles. For example an object should have only a single responsibility.
But then again when you are moving to production, I think you should combine all the php files to a couple of single files to have lesser require
(I/O) statements. I/O is a performance killer.
I actually think it's not as black and white as that, but depends on how they are used. If you have a group of functions that will always be used together then from a purely performance point of view it makes sense to group them together in one file.
Basically you want to avoid making large models with shitloads of irrelevant code because all code you load and dont use is a waste, but at the same time you want to keep your number of file includes low.
Try to group your models taking a mixture of performance and logic into account.
精彩评论