O'Reilly logo
  • Robert Bowers thinks this is interesting:

Using the Factory Method Pattern to Control How Objects Are Created

Currently, the way in which tasks are written to and read from the tasklist file is spread out across the executable. If we centralize how this is done, we can simplify our main code and provide another testable unit to ensure the quality of our application. We’ll add a class method to Task that, given a filename, reads it and returns a list of Task instances. Since this method creates new objects, it’s called a factory method


Cover of Build Awesome Command-Line Applications in Ruby 2


Factory Methods