Magento 1.7 Models – Difference Between getModel(‘catalog/product’) and getSingleton(‘catalog/product’)

magento-1.7

I have seen both function in Magento Files,

What is deference between both function. and also where I use one of them function.

Which is best to load Product Collection.

Best Answer

Thanks Amit for the great links, but because we don't have the answer here yet, we can not close the questions a duplicate, so here is the answer:

Magento wants to introduce with Mage::getSingleton() the Singleton design pattern. If I understand it correctly it is not exactly a singleton, because Mage takes care of only ONE instance. But fact is, if you are using Mage::getSingleton, you get the same object over and over again throughout all your code.

Mage::getModel() is just a standard factory and returns a newly created object of whatever type

So depending on you want to write to the same or a different object, you use either getSingleton or getModel