Technology

JavaScript – Factory Pattern

GitHub Code

This will be a short post.  The Factory pattern (usually) makes use of an abstract factory class and abstract object class.  Then, concrete implementations of the factory are created.  Once the base method (in this case it is ‘createObject()’) is called, a concrete object is made from the abstract object.

To run:

  • Make Get Call

Screen Shot 2017-04-27 at 11.41.57 AM

  • Review output

Screen Shot 2017-04-27 at 11.42.05 AM

Using the Object.create(args) method, a factory is created from AbsFactory.js.  When createObject() is called, a concrete object is created from AbsObject.js.

Screen Shot 2017-04-27 at 11.42.23 AM

Screen Shot 2017-04-27 at 11.42.52 AM

Stay tuned!

References

  1. https://www.tutorialspoint.com/design_pattern/factory_pattern.htm

One thought on “JavaScript – Factory Pattern

Leave a comment