Our Blog

Home » Deeper in to NetSuite » Using Factory Pattern to Implement Client Specific Functionality

Using Factory Pattern to Implement Client Specific Functionality

In this post, we’ll see how we can use Factory Pattern method (http://www.dofactory.com/javascript/factory-method-design-pattern) to implement client specific logic in our code.

You can use factory method design pattern in scenarios where you think the underlying implementation may vary based on parameters at run-time. This is a usual occurrence when working with NetSuite customization related tasks, because you may want to use the same code base for different clients.

While working on our Folio3 Magento Connector for NetSuite, we came across a similar scenario. Basically, we wanted to implement the following functionality  for different clients in different ways:

  • Setting Customer Fields
  • Setting Sales Order Information
  • Creating a Lead within NetSuite

To do so, we used the Factory Design Pattern method in our NetSuite Magento Connector’s code. Basically, we used a class in our code named F3ClientFactory, that was responsible for creating objects based on the current client.

For representing the functionality of all clients, we used a base class called F3ClientBase. This class contained all base functionality that we need to achieve. To override any of the methods, we used client specific classes which could override any method in which we wanted to implement different behavior.

You can use the Factory Design Pattern Method in all of your NetSuite customization code, which will enable you to have a single code base with varied underlying implementations.


Recent Comments

Leave a Reply

Your email address will not be published. Required fields are marked *