diff --git a/w11-patterns/w8_factory/index.html b/w11-patterns/w8_factory/index.html new file mode 100644 index 0000000..9b653f4 --- /dev/null +++ b/w11-patterns/w8_factory/index.html @@ -0,0 +1,11 @@ + + + +
+ + + + + + + \ No newline at end of file diff --git a/w11-patterns/w8_factory/index.js b/w11-patterns/w8_factory/index.js new file mode 100644 index 0000000..76100d3 --- /dev/null +++ b/w11-patterns/w8_factory/index.js @@ -0,0 +1,26 @@ +class Computer { + constructor(brand, os, ram, cpu, ssdSize) { + this.brand = brand; + this.os = os; + this.ram = ram; + this.cpu = cpu; + this.ssd = ssdSize; + } + + showSpects() { + console.log( + `Brand is ${this.brand} with ${this.os} OS. + CPU: ${this.cpu} / RAM: ${this.ram} / SSD size: ${this.ssd} + ` + ); + } +} + +// 1. Create a Builder for this +class ComputerBuilder {} + +// 2. Create a factory +// 3. Change it using a singleton +class ComputerFactory {} + +console.log('ready'); diff --git a/w11-patterns/w8_observer/Subject.js b/w11-patterns/w8_observer/Subject.js new file mode 100644 index 0000000..a1bf272 --- /dev/null +++ b/w11-patterns/w8_observer/Subject.js @@ -0,0 +1,5 @@ +class Subject {} + +class Observer {} + +export { Subject, Observer }; diff --git a/w11-patterns/w8_observer/index.html b/w11-patterns/w8_observer/index.html new file mode 100644 index 0000000..56c1da0 --- /dev/null +++ b/w11-patterns/w8_observer/index.html @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/w11-patterns/w8_observer/index.js b/w11-patterns/w8_observer/index.js new file mode 100644 index 0000000..7e10f7f --- /dev/null +++ b/w11-patterns/w8_observer/index.js @@ -0,0 +1,44 @@ +import { Observer, Subject } from './Subject.js'; + +class Fish { + constructor(weight) { + super(); + this.weight = weight; + } + getWeight() { + return this.weight; + } + getSpecies() { + return this.species; + } +} + +class Salmon extends Fish { + constructor() { + super(2); + this.species = 'Atalntinc salmon'; + } +} + +class Tuna extends Fish { + constructor() { + super(200); + this.species = 'Bluefin tuna'; + } +} + +class Fisherman { + constructor(name) { + super(); + this.name = name; + } +} + +// Main +const bob = new Fisherman('Bob'); + +const fish1 = new Tuna(); +const fish2 = new Salmon(); +// 1. subsribe bob (observer) to fish1 and fish2 (subjects) + +// 2. fishes (subjects) notify when they are caught