Factories and entities
The Factory Method Pattern is an object-oriented creational design pattern that implements the concept of factories. You can create objects without basing it on a specific class. The core of this pattern is to define an interface for creating an object, but let the classes that implement the interface decide which class to instantiate. The Factory method lets a class defer instantiation to subclasses.
To configure the entity factory to use, set the type. By default, the Sitecore Factory is used implicitly through Connect:
To configure custom objects in the Sitecore.Commerce.Carts.config file:
In an actual Connect provider implementation, the custom objects are known and do not necessarily have to be created through use of Factory.
You can use references to the factory as a parameter in some processors, for example, CreateCart:
You must use the Factory.Create method to get an instance of the needed type. For example, in the following code snippet, we need a cart and call the factory to create and return a cart. The cart domain model can be completely modified and customized so that you can replace the default cart type with your own implementation: