Skip to main content

Posts

Showing posts with the label eager initialization

VBA versus .NET

Singleton

The Singleton design pattern seems generally frowned upon, except for use in logging classes.  Below are several variants of the Singleton design pattern, of which, only the thread-safe version merits attention: Salient Chacteristic(s) A private constructor Static variable for self-tracking Three (3) variants Eager Lazy Thread-safe (Double-checked Locking) Code namespace DesignPatterns {     //double-checked locking singleton     //required for threaded environments     public class DoubleCheckingSingleton     {         private static volatile DoubleCheckingSingleton _Instance = null;         private static object _SyncRoot = new object();              //Private constructor prevents instantiation from other classes         private DoubleCheckingSingleton()         {        ...