Question about the customer class

Nov 14, 2009 at 1:34 AM

Why is the constructor for the Customer class marked as protected? What is the benefit of using static methods to create customers? By the way, thank you for creating the sample and article, both have been extremely helpful. I hope to construct all my future applications using the MVVM design pattern.

public static Customer CreateNewCustomer()
    return new Customer();

public static Customer CreateCustomer(
    double totalSales,
    string firstName,
    string lastName,
    bool isCompany,
    string email)
    return new Customer
        TotalSales = totalSales,
        FirstName = firstName,
        LastName = lastName,
        IsCompany = isCompany,
        Email = email

protected Customer()

Nov 14, 2009 at 6:42 PM

For this demo, it was unnecessary.  In general, though, I find it can be useful to use factory methods to create objects, instead of new()'ing them.  By using a factory method, you make it easier to refactor the code later to change the way that objects are created and initialized, without having to change all the places that request a new object.