Documentation

Model Factory

Version 1.2   |   Last Updated: 1/28/2014 (v1.2)   |  

When module data records are returned from the Zoho API, the ZohoSharp library must have a mechanism for knowing what type of strongly-typed objects to create. The library defines an ICRMModelFactory interface with a single CreateModel method for defining the model creation logic (and type) for each CRM module (either a built-in module or a custom module). When defining custom model classes (either representing new modules or customizations of built-in modules), this interface is implemented to generate the custom model objects.

The library provides a CRMModelFactoryBase class which is the default implementation of the ICRMModelFactory interface. It generates strongly typed, base CRM model objects – either POCO objects or objects that implement ISyncableModel (see the SyncableModelBase Models section). The CRMModelFactoryBase contains properties and the constructor accepts option parameters to determine whether to use the default POCO models or the SyncableModelBase models, to disable property change notifications on all models (disablePropertyNotifications – applies to SyncableModelBase models only) and to disable tracking of the model state and property states on all models (disableStateTracking – applies to SyncableModelBase models only). If these ISyncableModel features are not needed in your application they can simply be turned off through a CRMModelFactoryBase derivation. The default implementation of CRMModelFactoryBase.CreateModel returns base model types for the built-in Zoho CRM modules. For all other strings it returns a CustomModuleBase (deriving from CRMModelBase) or a CustomModuleSyncableBase (deriving from CRMSyncableModelBase) model object (depending on the model type setting).

When defining custom model classes (either representing new modules or customizations of built-in modules), this class can be subclassed with the CreateModel method overridden to return custom model objects for a string representation of the custom module or to specify a new model type for one or more built-in modules. When overriding this method, the base method should be called to ensure that a base model is always returned for the built-in modules for which the overriding method does not replace.

An ICRMModelFactory object should be provided to the ZohoCRMClient object in its constructor. If it is not, the default CRMModelFactoryBase class will be used.

The provided code samples demonstrate a custom model factory implementation.