Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ca135d8

Browse files
Add description and use fields to creational patterns
1 parent 862d40e commit ca135d8

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

‎src/static/patterns/creational_abstractFactory.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ const ABSTRACT_FACTORY = {
22
id: 'abstract_factory',
33
name: 'Abstract Factory',
44
type: 'creational',
5-
hint: 'groups object factories that have a common theme',
5+
hint: 'Creates an instance of several families of classes',
6+
description: `Rather than building a concrete object, it’s building a family of
7+
related or dependent objects without specifying concrete class.`,
8+
use: `system should be independent of how what it is producing is structured or represented`,
69
codeES5: `function droidProducer(kind) {
710
if (kind === 'battle') return battleDroidPattern;
811
return pilotDroidPattern;

‎src/static/patterns/creational_builder.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ const BUILDER = {
22
id: 'builder',
33
name: 'Builder',
44
type: 'creational',
5-
hint: 'constructs complex objects by separating construction and representation',
5+
hint: 'Separates object construction from its representation',
6+
description: `Separate how object is created from its representation,
7+
so the same process of creation can generate different representations.`,
8+
use: `algorithm of creation is independent of the parts of the object`,
69
codeES5: `function Request() {
710
this.url = '';
811
this.method = '';

‎src/static/patterns/creational_factory.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ const FACTORY = {
22
id: 'factory',
33
name: 'Factory',
44
type: 'creational',
5-
hint: 'creates objects without specifying the exact class to create',
5+
hint: 'Creates an instance of several derived classes',
6+
description: `Gives an interface to build an object but let subclasses to decide which class to instantiate.`,
7+
use: `a class wants its subclasses to decide which object to create`,
68
codeES5: `function teslaPattern(type) {
79
if (type === 'ModelX') return new Tesla(type, 108000, 300);
810
if (type === 'ModelS') return new Tesla(type, 111000, 320);

‎src/static/patterns/creational_prototype.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ const PROTOTYPE = {
22
id: 'prototype',
33
name: 'Prototype',
44
type: 'creational',
5-
hint: 'creates objects by cloning an existing object',
5+
hint: 'A fully initialized instance to be copied or cloned',
6+
description: `Create objects by copying prototypical instance of them.`,
7+
use: `classes to instantiate are available only in runtime`,
68
codeES5: `function Sheep(name, weight) {
79
this.name = name;
810
this.weight = weight;

‎src/static/patterns/creational_singleton.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ const SINGLETON = {
22
id: 'singleton',
33
name: 'Singleton',
44
type: 'creational',
5-
hint: 'restricts object creation for a class to only one instance',
5+
hint: 'A class of which only a single instance can exist',
6+
description: `Ensures that a class has only one instance and gives global access to it.`,
7+
use: `there must by only one instance of a class`,
68
codeES5: `function Person() {
79
if (typeof Person.instance === 'object') return Person.instance;
810

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /