factory method

The factory method pattern is a pattern that uses methods to deal with the problem of creating objects without having to specify the exact class of the object that will be created. This is done by creating objects by calling a factory method—either specified in an interface and implemented by child classes, or implemented in a base class and optionally overridden by derived classes—rather than by calling a constructor.
In "Factory Method" an object has a method which is responsible for the instantiation of another object. A common example would be the JavaScript document object and the creation of HtmlElement objects:
```
var newDiv = document.createElement('div');
```
This isn't a great example though, as an important part of the Factory Method is polymorphism. If I could extend document to define another class which defines another createElement this would be prime Factory Method material.
In OOP languages this generally involves separate classes that encapsulate the business logic of creating objects and that can decide which object create during runtime. This often involves setting specific parameters on the created object depending on what we want to instantiate.
In FP, higher-order functions give us a simple solution, instead of having behavior being defined by classes an inheritance, we just return a function that encapsulates the desired behavior or object.