How to use the Facade.Instance method without object construction?

292 views Asked by At

I only recently completed a unit on software patterns and am now attempting to comprehend the PureMVC framework. One thing has got my stumped however, something which is simple to the gurus here.

I'm attempting to create an instance of the singleton Facade class. In the constructor, the comments state:

This IFacade implementation is a Singleton, so you should not call the constructor directly, but instead call the static Singleton Factory method Facade.Instance

How can you call the instance method when the Facade object has not even been created?

The Facade.Instance method looks like this:

public static IFacade Instance
    {
        get
        {
            if (m_instance == null)
            {
                lock (m_staticSyncRoot)
                {
                    if (m_instance == null) m_instance = new Facade();
                }
            }

            return m_instance;
        }
    }
1

There are 1 answers

0
jrista On BEST ANSWER

You are accessing a static property. Static properties are part of the class definition, not class instances. To access a static member (property, field, method), simply use the class name dot member:

var myFacade = SomeClass.Instance;