vendredi 7 décembre 2018

C# Singleton design pattern basics

Just recently started to try and learn some designs patterns. Currently trying to get my singleton to return a new object. However it keeps throwing the error "Cannot convert method group 'getInstance' to non-delegate type 'MainWdinow.CustomerLoader'. did you intend to invoke the method?

here is the code for the design pattern method

  public class CustomerLoader
    {
        private static Train firstInstance = null;
        public static Train getInstance()
        {
            if(firstInstance ==null)
            {
                firstInstance = new Customer();
            }

            return firstInstance;
        }
    }

Here is where I try to call the method and I get the error mentioned above

CustomerLoader t = CustomerLoader.getInstance;

I want my singleton to do the job of the code below and create a new instance of the customer object

Customer T = new Customer;

Aucun commentaire:

Enregistrer un commentaire