The example of factory pattern is misleading. Although the definition says,
Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.
But the example doesn't use any subclasses at all. Whereas, Addy Osmani's example explains it pretty well.
The example of factory pattern is misleading. Although the definition says,
But the example doesn't use any subclasses at all. Whereas, Addy Osmani's example explains it pretty well.