Studyon Minte9.com
Magento




Class Overrides



Finally, the Magento System offers you the ability to replace Model, Helper and Block classes from the core 
modules with your own. Here's an example to help you understand. The Model class for a product is 
Mage_Catalog_Model_Product. 

	$product = Mage::getModel('catalog/product'); 

This is a factory pattern. 

You can change the behavior of any method on the class, but keep the functionality of the existing methods.

	class Packagename_Modulename_Model_Foobazproduct extends Mage_Catalog_Model_Product
	{
	    public function validate()
	    {
		//add custom validation functionality here
		return $this;
	    }

	} 

As you might expect, this overriding (or rewriting) is done in the config.xml file.

	<models>
	    <!-- tells the system this module has models -->
	    <modulename>
		<class>Packagename_Modulename_Model</class>
	    </modulename>

	    <!-- does the override for catalog/product-->
	    <catalog>  
		<rewrite>
		    <product>Packagename_Modulename_Model_Foobazproduct</product>
		</rewrite>
	    </catalog>          
	</models> 


http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-1-introduction-to-magento#9