"JS design mode" Review simple Factory mode, factory method mode, abstract Factory mode concept

Source: Internet
Author: User

Note: A hollow arrow represents an inheritance relationship, and a dependency between a factory class and a product class. is indicated by the arrows with the dotted line, the following model diagram is used by the solid lines is not correct (time is not enough, I am lazy here.) This habit is not good, hehe)
Simple Factory Pattern: Use a class (usually a monomer) to create an instance, and a simple factory pattern called a static factory method pattern (static FactoryMethod pattern).
The definition of an interface is usually preceded by an I identifier, which does not define the syntax of an interface or abstract class in JS;
var macbikefactory = {  createbike:function () {    return new macbike ();}  } function Imacbike () {}function macbike () {}macbike.prototype = {  constructor:macbike,  getbike:function () {
   console.log ("Create a Mac Car");}  } var MACFN = Macbikefactory.createbike (); Macfn.getbike ();

The factory method pattern uses subclasses to determine which instance of a member variable should be the detailed class

function Imacbikefactory () {}function macbikefactory ()  {  this.createbike () {    return new macbike ();}  } function Imacbike () {}function macbike () {}macbike.prototype = {  constructor:macbike,  getbike:function () {
   console.log ("Create a Mac Car");  

In the simple factory model, a single unit is used to instantiate a detailed product, whereas in the factory method pattern the instantiated process is given to the subclass of the abstract factory to create
Abstract Factory mode multiple abstract product classes, each abstract product class can derive a number of detailed product classes.
An abstract factory class that can derive multiple detailed factory classes.
Each detailed factory class is able to create instances of more than one detailed product class.




There are two abstract products ibike and icar classes, each of which derive two detailed products with a Imall abstract factory class that derives two detailed factory aMALL and Bmall classes each detailed factory class can also create multiple detailed product instances aMALL stores sells Baoma brand cars and Fenghuang brands of bicycles, Bmall stores sells Falali branded cars and jieante brands of bicycles

"JS design mode" Review simple Factory mode, factory method mode, abstract Factory mode concept

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.