Skip to content

Commit 727555f

Browse files
committed
Add hint and id to patterns in data file
1 parent aae421b commit 727555f

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

src/data/patterns.js

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ const patterns = [
33
* Abstract
44
*/
55
{
6+
id: 'abstract_factory',
67
name: 'Abstract Factory',
78
type: 'creational',
9+
hint: 'groups object factories that have a common theme',
810
codeES5: `function droidProducer(kind) {
911
if (kind === 'battle') return battleDroidPattern;
1012
return pilotDroidPattern;
@@ -60,8 +62,10 @@ export default droidProducer;`
6062
* Builder
6163
*/
6264
{
65+
id: 'builder',
6366
name: 'Builder',
6467
type: 'creational',
68+
hint: 'constructs complex objects by separating construction and representation',
6569
codeES5: `function Request() {
6670
this.url = '';
6771
this.method = '';
@@ -131,8 +135,10 @@ export default RequestPattern;`
131135
* Factory
132136
*/
133137
{
138+
id: 'factory',
134139
name: 'Factory',
135140
type: 'creational',
141+
hint: 'creates objects without specifying the exact class to create',
136142
codeES5: `function teslaPattern(type) {
137143
if (type === 'ModelX') return new Tesla(type, 108000, 300);
138144
if (type === 'ModelS') return new Tesla(type, 111000, 320);
@@ -166,8 +172,10 @@ export default TeslaPattern;`
166172
* Prototype
167173
*/
168174
{
175+
id: 'prototype',
169176
name: 'Prototype',
170177
type: 'creational',
178+
hint: 'creates objects by cloning an existing object',
171179
codeES5: `function Sheep(name, weight) {
172180
this.name = name;
173181
this.weight = weight;
@@ -195,8 +203,10 @@ export default Sheep;`
195203
* Singleton
196204
*/
197205
{
206+
id: 'singleton',
198207
name: 'Singleton',
199208
type: 'creational',
209+
hint: 'restricts object creation for a class to only one instance',
200210
codeES5: `function Person() {
201211
if (typeof Person.instance === 'object') return Person.instance;
202212
@@ -222,8 +232,11 @@ export default Person;`
222232
* Adapter
223233
*/
224234
{
235+
id: 'adapter',
225236
name: 'Adapter',
226237
type: 'structural',
238+
hint:
239+
'allows classes with incompatible interfaces to work together by wrapping its own interface around that of an already existing class',
227240
codeES5: `function Soldier(lvl) {
228241
this.lvl = lvl;
229242
}
@@ -285,8 +298,10 @@ export { Soldier, Jedi, JediPattern };`
285298
* Bridge
286299
*/
287300
{
301+
id: 'bridge',
288302
name: 'Bridge',
289303
type: 'structural',
304+
hint: 'decouples an abstraction from its implementation so that the two can vary independently',
290305
codeES5: `function EpsonPrinter(ink) {
291306
this.ink = ink();
292307
}
@@ -363,8 +378,10 @@ export { EpsonPrinter, HPprinter, AcrylicInk, AlcoholInk };`
363378
* Composite
364379
*/
365380
{
381+
id: 'composite',
366382
name: 'Composite',
367383
type: 'structural',
384+
hint: 'composes zero-or-more similar objects so that they can be manipulated as one object',
368385
codeES5: `function EquipmentPattern(name) {
369386
this.equipments = [];
370387
this.name = name;
@@ -484,8 +501,10 @@ export { Cabbinet, FloppyDisk, HardDrive, Memory };`
484501
* Decorator
485502
*/
486503
{
504+
id: 'decorator',
487505
name: 'Decorator',
488506
type: 'structural',
507+
hint: 'dynamically adds/overrides behaviour in an existing method of an object',
489508
codeES5: `function Pasta() {
490509
this.price = 0;
491510
}
@@ -568,8 +587,10 @@ export { Penne, SaucePattern, CheesePattern };`
568587
* Facade
569588
*/
570589
{
590+
id: 'facade',
571591
name: 'Facade',
572592
type: 'structural',
593+
hint: 'provides a simplified interface to a large body of code',
573594
codeES5: `var shopPattern = {
574595
calc: function(price) {
575596
price = discount(price);
@@ -631,8 +652,10 @@ export default ShopPattern;`
631652
* Flyweight
632653
*/
633654
{
655+
id: 'flyweight',
634656
name: 'Flyweight',
635657
type: 'structural',
658+
hint: 'reduces the cost of creating and manipulating a large number of similar objects',
636659
codeES5: `function Color(name) {
637660
this.name = name;
638661
}
@@ -673,8 +696,11 @@ export { colorCreator };`
673696
* Proxy
674697
*/
675698
{
699+
id: 'proxy',
676700
name: 'Proxy',
677701
type: 'structural',
702+
hint:
703+
'provides a placeholder for another object to control access, reduce cost, and reduce complexity',
678704
codeES5: `function Car() {
679705
this.drive = function() {
680706
return 'driving';
@@ -721,8 +747,10 @@ export { Car, CarPattern, Driver };`
721747
* Chain of Resp
722748
*/
723749
{
724-
name: 'Chain of Resp',
750+
id: 'chain_of_responsibility',
751+
name: 'Chain of Responsibility',
725752
type: 'behavioral',
753+
hint: 'delegates commands to a chain of processing objects',
726754
codeES5: `function ShoppingCart() {
727755
this.products = [];
728756
@@ -851,8 +879,10 @@ export { ShoppingCart, Discount };`
851879
* Command
852880
*/
853881
{
882+
id: 'command',
854883
name: 'Command',
855884
type: 'behavioral',
885+
hint: 'creates objects which encapsulate actions and parameters',
856886
codeES5: `function Cockpit(instruction) {
857887
this.instruction = instruction;
858888
}
@@ -961,8 +991,10 @@ export { Cockpit, Turbine, OnInstruction, OffInstruction };`
961991
* Interpreter
962992
*/
963993
{
994+
id: 'interpteter',
964995
name: 'Interpreter',
965996
type: 'behavioral',
997+
hint: 'implements a specialized language',
966998
codeES5: `function Sum(left, right) {
967999
this.left = left;
9681000
this.right = right;
@@ -1028,8 +1060,11 @@ export { Num, Min, Sum };`
10281060
* Iterator
10291061
*/
10301062
{
1063+
id: 'iterator',
10311064
name: 'Iterator',
10321065
type: 'behavioral',
1066+
hint:
1067+
'accesses the elements of an object sequentially without exposing its underlying representation',
10331068
codeES5: `function Pattern(el) {
10341069
this.index = 0;
10351070
this.elements = el;
@@ -1066,8 +1101,11 @@ export default Pattern;`
10661101
* Mediator
10671102
*/
10681103
{
1104+
id: 'mediator',
10691105
name: 'Mediator',
10701106
type: 'behavioral',
1107+
hint:
1108+
'allows loose coupling between classes by being the only class that has detailed knowledge of their methods',
10711109
codeES5: `function TrafficTower() {
10721110
this.airplanes = [];
10731111
}
@@ -1119,8 +1157,10 @@ export { TrafficTower, Airplane };`
11191157
* Memento
11201158
*/
11211159
{
1160+
id: 'memento',
11221161
name: 'Memento',
11231162
type: 'behavioral',
1163+
hint: 'provides the ability to restore an object to its previous state',
11241164
codeES5: `function Pattern(value) {
11251165
this.value = value;
11261166
}
@@ -1182,8 +1222,11 @@ export { originator, Caretaker };`
11821222
* Observer
11831223
*/
11841224
{
1225+
id: 'observer',
11851226
name: 'Observer',
11861227
type: 'behavioral',
1228+
hint:
1229+
'is a publish/subscribe pattern which allows a number of observer objects to see an event',
11871230
codeES5: `function Product() {
11881231
this.price = 0;
11891232
this.actions = [];
@@ -1273,8 +1316,10 @@ export { Product, fees, proft };`
12731316
* State
12741317
*/
12751318
{
1319+
id: 'state',
12761320
name: 'State',
12771321
type: 'behavioral',
1322+
hint: 'allows an object to alter its behavior when its internal state changes',
12781323
codeES5: `function Order() {
12791324
this.pattern = new WaitingForPayment();
12801325
@@ -1350,8 +1395,10 @@ export default Order;`
13501395
* Strategy
13511396
*/
13521397
{
1398+
id: 'strategy',
13531399
name: 'Strategy',
13541400
type: 'behavioral',
1401+
hint: 'allows one of a family of algorithms to be selected on-the-fly at runtime',
13551402
codeES5: `function ShoppingCart(discount) {
13561403
this.discount = discount;
13571404
this.amount = 0;
@@ -1411,8 +1458,11 @@ export { ShoppingCart, guestPattern, regularPattern, premiumPattern };`
14111458
* Template
14121459
*/
14131460
{
1461+
id: 'template',
14141462
name: 'Template',
14151463
type: 'behavioral',
1464+
hint:
1465+
'defines the skeleton of an algorithm as an abstract class, allowing its subclasses to provide concrete behavior',
14161466
codeES5: `function Tax() {}
14171467
14181468
Tax.prototype.calc = function(value) {
@@ -1476,8 +1526,11 @@ export { Tax1, Tax2 };`
14761526
* Visitor
14771527
*/
14781528
{
1529+
id: 'visitor',
14791530
name: 'Visitor',
14801531
type: 'behavioral',
1532+
hint:
1533+
'separates an algorithm from an object structure by moving the hierarchy of methods into one object',
14811534
codeES5: `function bonusPattern(employee) {
14821535
if (employee instanceof Manager) employee.bonus = employee.salary * 2;
14831536
if (employee instanceof Developer) employee.bonus = employee.salary;

0 commit comments

Comments
 (0)