Why make a public method to call a private constructor?

I'm reading up on INotifyPropertyChanged and I find this little jewel.

// The constructor is private to enforce the factory pattern. customerNameValue = String.Empty(); phoneNumberValue = String.Empty(); private DemoCustomer() { customerNameValue = "Customer"; phoneNumberValue = "(312)555-0100"; } // This is the public factory method. public static DemoCustomer CreateNewCustomer() { return new DemoCustomer(); } 

They create a private Constructor, then a public method to return the newly-constructed object. This looks somewhat like the practice of writing Getters and Setters, the purpose of which I understand (to a degree, at least). But I'm not so sure why this would be done with Constructors.

Why would anyone want to do this instead of simply creating public Constructors? I think maybe it has to do with the static property, but I still don't quite get it unless they are simply trying to create a different model for OOP.

by ryokimball via /r/csharp

Leave a Reply