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
Advertisements

One thought on “JavaScript – Factory Pattern

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s