$> git checkout factory_method
Intent
Define an interface for creating an object, but let subclasses decide which class to instantiate. The factory method lets a class defer instantiation to subclasses.1
Applications
When you are creating variations of some thing, you can break those variations into separate product classes . However, these classes may be difficult to construct, so you create accompanying factories for each product. Factories can be used to replace or refactor class constructors so that no logic exists inside the product class constructor . This pattern differs from the abstract ...