Skip to content

Commit 4991cfd

Browse files
committed
Move code to ES2015
- Review all the Design Patterns - Add a new Design Pattern exclusive only for ES6 [Multi-inheritance] - Modify README.md to: - Include the new pattern. - Order the patterns alphabetically. - Add Babel.js information.
1 parent b8901ed commit 4991cfd

File tree

111 files changed

+784
-622
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+784
-622
lines changed

Command/1/scripts/Command.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Command {
2-
execute() {
3-
throw new Error('This method must be overwritten!');
4-
}
2+
execute() {
3+
throw new Error('This method must be overwritten!');
4+
}
55
}
66

77
export default Command;
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import LightOnCommand from '../../common/LightOnCommand';;
1+
import LightOnCommand from '../../common/LightOnCommand';
2+
;
23

3-
class LightOnCommand2 extends LightOnCommand{
4-
undo() {
5-
this.light.off();
6-
}
4+
class LightOnCommand2 extends LightOnCommand {
5+
undo() {
6+
this.light.off();
7+
}
78
}
89

910
export default LightOnCommand2;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import SimpleRemoteControl from '../../common/SimpleRemoteControl';
22

33
class SimpleRemoteControl2 extends SimpleRemoteControl {
4-
buttonUndoWasPressed() {
5-
this.command.undo();
6-
}
4+
buttonUndoWasPressed() {
5+
this.command.undo();
6+
}
77
}
88

99
export default SimpleRemoteControl2;

Composite/scripts/Mattress.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
class Mattress {
22
constructor(aMenus) {
3-
this.aMenus = aMenus;
3+
this.menus = aMenus;
44
}
55

66
printMenu() {
7-
this.aMenus.print();
7+
this.menus.print();
88
}
99
}
1010

Composite/scripts/MenuComponent.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
11
class MenuComponent {
2+
constructor(name = '', description = '', isVegetarian = false, price = 0) {
3+
this.name = name;
4+
this.description = description;
5+
this._isVegetarian = isVegetarian;
6+
this.price = price;
7+
}
8+
29
getName() {
3-
throw new Error('This method must be overwritten!');
10+
return this.name;
411
}
512

613
getDescription() {
7-
throw new Error('This method must be overwritten!');
14+
return this.description;
815
}
916

1017
getPrice() {
11-
throw new Error('This method must be overwritten!');
18+
return this.price;
1219
}
1320

1421
isVegetarian() {
15-
throw new Error('This method must be overwritten!');
22+
return this._isVegetarian;
1623
}
1724

1825
print() {
19-
throw new Error('This method must be overwritten!');
26+
shouldBeOverwritten();
2027
}
2128

2229
add() {
23-
throw new Error('This method must be overwritten!');
30+
shouldBeOverwritten();
2431
}
2532

2633
remove() {
27-
throw new Error('This method must be overwritten!');
34+
shouldBeOverwritten();
2835
}
2936

3037
getChild() {
31-
throw new Error('This method must be overwritten!');
38+
shouldBeOverwritten();
3239
}
3340
}
3441

Composite/scripts/MenuItem.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,6 @@
11
import MenuComponent from './MenuComponent';
22

33
class MenuItem extends MenuComponent {
4-
constructor(name, description, isVegetarian, price) {
5-
super();
6-
this.name = name;
7-
this.description = description;
8-
this._isVegetarian = isVegetarian;
9-
this.price = price;
10-
return this;
11-
}
12-
13-
getName() {
14-
return this.name;
15-
}
16-
17-
getDescription() {
18-
return this.description;
19-
}
20-
21-
getPrice() {
22-
return this.price;
23-
}
24-
25-
isVegetarian() {
26-
return this._isVegetarian;
27-
}
28-
294
print() {
305
console.log(this.getName() + ": " + this.getDescription() + ", " + this.getPrice() + "euros");
316
}

CompositeIterator/1/index.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<div id="source">
88
<h2>Source</h2>
99
<pre>
10-
import Menu from './Menu';
11-
import MenuItem from './MenuItem';
12-
import Mattress from './Mattress';
10+
import Menu from '../../common/Menu';
11+
import MenuItem from '../../common/MenuItem';
12+
import Mattress from '../../common/Mattress';
1313

1414
var oPanCakeHouseMenu = new Menu("Pancake House Menu", "Breakfast");
1515
var oDinnerMenu = new Menu("Dinner Menu", "Lunch");
@@ -31,7 +31,6 @@ <h2>Source</h2>
3131
console.log("---------------------------------------------");
3232
oMattress.printMenu();
3333
console.log("---------------------------------------------");
34-
3534
</pre>
3635
</div>
3736
<div id="console">

CompositeIterator/2/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<div id="source">
88
<h2>Source</h2>
99
<pre>
10-
import Menu from './Menu';
11-
import MenuItem from './MenuItem';
10+
import Menu from '../../common/Menu';
11+
import MenuItem from '../../common/MenuItem';
1212
import Mattress from './Mattress';
1313

1414
let panCakeHouseMenu = new Menu("Pancake House Menu", "Breakfast");
@@ -25,13 +25,13 @@ <h2>Source</h2>
2525
3.89));
2626
dinnerMenu.add(coffeeMenu);
2727

28+
2829
coffeeMenu.add(new MenuItem("Express", "Coffee from machine", false, 0.99));
2930

3031
let mattress = new Mattress(allMenus);
3132
console.log("---------------------------------------------");
3233
mattress.printVegetarianMenu();
3334
console.log("---------------------------------------------");
34-
3535
</pre>
3636
</div>
3737
<div id="console">

CompositeIterator/2/scripts/Mattress.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@ import Mattress from '../../common/Mattress';
22

33
class Mattress2 extends Mattress {
44
printVegetarianMenu() {
5-
let iterator = this.menus.createIterator();
5+
let iterator = this.menus.menuComponents[Symbol.iterator]();
6+
let menu = iterator.next();
67
console.log("VEGETARIAN MENU");
7-
while (iterator.hasNext()) {
8-
let menuComponent = iterator.next();
9-
try {
10-
if (menuComponent.isVegetarian()) {
11-
menuComponent.print();
12-
}
13-
} catch (error) {}
8+
while (menu.value) {
9+
let menuComponentsIterator = menu.value.menuComponents[Symbol.iterator]();
10+
let menuComponent = menuComponentsIterator.next();
11+
while (menuComponent.value) {
12+
try {
13+
if (menuComponent.value.isVegetarian()) {
14+
menuComponent.value.print();
15+
}
16+
} catch (error) {}
17+
menuComponent = menuComponentsIterator.next();
18+
}
19+
menu = iterator.next();
1420
}
1521
}
1622
}

CompositeIterator/common/CompositeIterator.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)