Factory Method Pattern
Defines an interface for creating an object, but lets subclasses decide which class to instantiate. Factory method lets a class defer instantiation to subclasses.
Head First Design Patterns
This design pattern will come in handy when we want a character generator that will not only build SuperHeroes but Fantasy Heroes as well. We define an interface and build different hero creators from this interface. These hero creators will then build heroes. All the files can be downloaded.
Finally we can build these classes and objects in Ruby as seen in the following code. One difference between the code and the class diagram is that Ruby doesn’t need to define the abstract classes. Nor does it need to define separate creators for the Fantasy and Super Heros such as Java would have to do.
Factory-Method-Pattern.rbtags: design patterns