GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — JavaScript-Design-Patterns/GoF/idiomatic/Creational/Factory at master · irynaO/JavaScript-Design-Patterns

Expand file tree

/

Factory

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
 
 
/

Factory

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
CoffeeScript
CoffeeScript
 
 
ECMAScript
ECMAScript
 
 
TypeScript
TypeScript
 
 
Factory.dia
Factory.dia
 
 
Factory.png
Factory.png
 
 
README.md
README.md
 
 

README.md

Outline

Synopsis

I am a fan of GNU/Linux distributions and I want to test the big names: Debian, RedHat, Slackware.

Problem

Debian, RedHat and Slackware are all Linux distributions. We could create directly an object literal to represent each one, but this is not necessarily the best choice. We are not sure to use each instance in our code and we do not want to use memory for nothing. For the sake of clarity and performance, it may be nice to delegate the instantiation logic.

Solution

Factory makes it possible to do so. To implement this design pattern, we only need to create a function that will return objects.

In JavaScript, a function or method that returns objects is generally considered as a factory. It is a well-known idiomatic alternative to the use of the "new" keyword along with constructor functions.

Factory (idiomatic)

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.