article

Factory Pattern Overview

[WHAT]

  1. ] by Don Sagrott, founder @ sospep.com - 
  2. ] factory pattern is a GoF pattern used in OOP that relies on a Factory object that has methods that generate other objects
  3. ] there are 3 methodogies for implementing a Factory - the Simple Factory, the Abstract Factory and the Factory Method  
  4. ] article by Rob Dodson explains each of the different methodologies and provides example code for implementing each. 
  5. ] article by Dofactory is  very simple javascript example of the impementation of the ...
  6. ] article by __ iJako .. implements 3 types of factories in php

[WHY]

[WHERE]

  1. ] READ THE FULL ARTICLE

[WHEN]

  1. ] 2017-05-28

[EXAMPLE]

factory pattern 

Factory method pattern - Wikipedia 

 

factory pattern - javascript 

JavaScript Design Patterns: Factory ] by Rob Dodson 

Dodson formally defines the Factory pattern the 3 different "versions" of implementing Factory designs . 

Factories encapsulate and separate object creation from the rest of your code. In situations where the creation of an object can be complex or subject to change a factory can act as a nice buffer to help keep things tidy. Without proper planning Factories can lead to class explosions; as a result the pattern can be both a blessing and a curse depending on how it's used.

Simple Factory - is an object which encapsulates the creation of another object, shielding that code from the rest of your application. It's common to parameterize simple factory methods to increase the number of products they're able to return. Typically the return value from a factory is known as the Product

Factory Method - Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses. (aka Virtual Constructor ) Factory Method defines one method, createThing for instance, which is overriden by subclasses who decide what to return. The Factories and Products must conform to interfaces for clients to be able to use them. The main take away is that there is only one method, (createPizza, )that does anything. By subclassing and overriding this method we can offer aditional flexibility beyond what's possible with the Simple Factory.

Abstract Factory - Provide an interface for creating families of related or dependent objects without specifying their concrete classes. ( aka Kit ) 

Dodson goes on to provide code implementations of each of the various implementations of the Factory design in JavaScript. The includes implementing an Abstract Factory in the JS language which lacks the language feature of being able to define an interface 

http://www.dofactory.com/javascript/factory-method-design-pattern -

A simple example, create different types of employees using a Factory with a createEmployee(type) method

A Factory Method creates new objects as instructed by the client. One way to create objects in JavaScript is by invoking a constructor function with the new operator. There are situations however, where the client does not, or should not, know which one of several candidate objects to instantiate. The Factory Method allows the client to delegate object creation while still retaining control over which type to instantiate.

The key objective of the Factory Method is extensibility. Factory Methods are frequently used in applications that manage, maintain, or manipulate collections of objects that are different but at the same time have many characteristics (i.e. methods and properties) in common. An example would be a collection of documents with a mix of Xml documents, Pdf documents, and Rtf documents. 

The Factory Pattern in JS ES6 – SntsDev – Medium 

 ....

[HOW-TO]

  1. ] Simple Factory - 
  2. ] Factory Method - 
  3. ] Abstract Factory - 

[REFERENCE]

  1. ] # 7235 CREATE-article# 5736 - Factory Pattern - overview

 

Details Photos Edit more

Details

ID: 5736

NAME: factory-pattern-overview

DESCRIPTION: ] factory pattern overview

AUTHOR: article.author/s

EDITOR: article.editor/s

PUBLISHER: article.publisher/s

STATUS: Write

PRIORITY: -5

OWNER ID: 75

Content Photos Edit more

photos

page_photo

actions

Email Email-Owner SMS and