locked
need help Creating Factory for COM object RRS feed

  • Question


  • Hi,

    I am trying to create a class factory for a COM object. Basically I want the COM factory to be able to do to perform the following functions.

    1) want the factory to be able to return an instance of the COM object to the calling function.

    2) Also if an instance of the COM object factory has already been created I want the existing instance of the COM object to be returned to any calling functions/classes.

    3) If the COM object Instance can't be created then I want the factory class to return appropriate error codes.


    if someone could posts some helpful links or point me in the right direction that would be extremely helpful.

    Thanks in advance.
    Tuesday, February 24, 2009 8:19 PM

Answers

  • You can use an adapter class with the singleton patter as follows



    using System;

    public sealed class Singleton
    {
       private static volatile Singleton instance;
       private static object syncRoot = new Object();

       private Singleton() {}

       public static Singleton Instance
       {
          get
          {
             if (instance == null)
             {
                lock (syncRoot)
                {
                   if (instance == null)
                      instance = new Singleton();
                }
             }

             return instance;
          }
       }
    }
     
    Monday, March 2, 2009 6:28 AM