When is it more logical to use the factory model rather than an overloaded constructor to instantiate an object?

advertisements

In Karl Seguin's Foundations of Programming there is a small section on using the factory pattern. He closes the passage by stating "you can accomplish the same functionality with constructor overloading", but doesn't indicate when or why?

So,when does it make more sense to use the factory pattern rather than an overloaded constructor to instantiate an object?


If you want to have looser coupling then the factory makes more sense, as you can then just call the car factory, pass in the suv enum, and the correct class is returned. Your application doesn't care which class was actually returned, as long as it meets your needs.