Implementing Singleton Design Pattern in Apex – Use Case I
This post is part of the series – Design Pattern in ApexSingleton Design Pattern is pretty popular and one of the simplest design pattern available. I will start with the statement from “The Gang of Four” as it describes Singleton Pattern as –“Ensure a class has only one instance, and provide a global point of access to it.”In this post, I will explain why we need to have Singleton Design Pattern in Apex and how to implement the same.Sometimes it is very much required to have only instances of the class – Logger, Window Manager etc. Typically, these type of objects where only one instance is sufficient to handle the requirements, are called Singleton.With Singleton Design Pattern, you can –Ensure that only one instance of class is getting created.Provide a global point of access to the object.There are many ways to implement Singleton Pattern in apex. Let’s start with few case scenarios:Use Case:Consider the below requirement -Whenever a new account is getting inserted to Salesforce, it should be synced with MDM(Master Data Management) through integration. But if MDM system is down, then Salesforce should not got for synchronization.Let’s start implementing the requirement -Custom Settings – Integration – This will be used to identify whether MDM System is up and running. If MDM System is down, Admin will uncheck the value and then Salesforce will not try for synchronization. Below is how...
Read More