Functions as Factories

Cocoa at Tumblr:

Factories are a fairly well understood design pattern in software development. The benefits of using factories include:

  1. Abstracting constructors away from clients.
  2. Encapsulating data that clients do not need to know about.
  3. Allowing for more testable code by enforcing the idea of passing objects into initializers instead of referencing singletons directly.

This post will show the power of a few Swift features as well as of first­-class functions.