Exemple #1
0
        //DOUBLE-CHECKED LOCKING
        public static ChocolateFactory GetInstance()
        {
            if (_instance == null)
            {
                lock (typeof(ChocolateFactory))
                {
                    if (_instance == null)
                    {
                        _instance = new ChocolateFactory();
                    }
                }
            }

            return(_instance);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            ChocolateFactory cf = ChocolateFactory.GetInstance();

            cf.Fill();

            ChocolateFactory cf2 = ChocolateFactory.GetInstance();

            cf.Boil();
            cf2.Fill();
            cf.Drain();
            cf2.Fill();
            cf2.Boil();
            cf2.Drain();


            Console.ReadKey();
        }