Skip to content

Commit

Permalink
after first presentational
Browse files Browse the repository at this point in the history
  • Loading branch information
fxcosta committed Sep 7, 2017
0 parents commit f6f8c93
Show file tree
Hide file tree
Showing 42 changed files with 774 additions and 0 deletions.
13 changes: 13 additions & 0 deletions creational/abstract-factory/maze.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const MazeGame = require ('./maze/MazeGame');

const BombedMazeFactory = require ('./maze/bombed/BombedMazeFactory');
const EnchantedMazeFactory = require ('./maze/enchanted/EnchantedMazeFactory');

const bombedGame = new BombedMazeFactory();
const enchantedGame = new EnchantedMazeFactory();

const mazeGame = new MazeGame();
const game = mazeGame.createMaze(enchantedGame);

console.log(game);
console.log(game.getRooms());
24 changes: 24 additions & 0 deletions creational/abstract-factory/maze/Door.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Door {

constructor(room1, room2) {
this.room1 = room1;
this.room2 = room2;
}

isOpen() {
return this.isOpen;
}

open() {
if (!this.isOpen) {
this.isOpen = !isOpen;
}
}

initialize(room1, room2) {
this.room1 = room1;
this.room2 = room2;
}
}

module.exports = Door;
20 changes: 20 additions & 0 deletions creational/abstract-factory/maze/Maze.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Maze {

constructor() {
this.rooms = [];
}

addRoom(room) {
this.rooms.push(room);
}

getRooms() {
return this.rooms;
}

clone () {
return new Maze();
}
}

module.exports = Maze;
27 changes: 27 additions & 0 deletions creational/abstract-factory/maze/MazeFactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const Door = require('./Door');
const Room = require('./Room');
const Maze = require('./Maze');
const Wall = require('./Wall');

class MazeFactory {

constructor() {}

makeMaze() {
return new Maze();
}

makeDoor(room1, room2) {
return new Door(room1, room2);
}

makeRoom(roomNumber) {
return new Room(roomNumber);
}

makeWall() {
return new Wall();
}
}

module.exports = MazeFactory;
20 changes: 20 additions & 0 deletions creational/abstract-factory/maze/MazeGame.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class MazeGame {

createMaze (factory) {
this.maze = factory.makeMaze();

let room1 = factory.makeRoom(1);
let room2 = factory.makeRoom(2);
let door = factory.makeDoor(room1, room2);

this.maze.addRoom(room1);

room1.setSide('north', factory.makeWall());
room1.setSide('south', door);

return this.maze;
}

}

module.exports = MazeGame;
20 changes: 20 additions & 0 deletions creational/abstract-factory/maze/Room.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Room {

constructor(number) {
this.roomNumber = number;

this.positions = [];
this.elements = [];
}

setNumber(number) {
this.roomNumber = number;
}

setSide(position, element) {
this.positions.push(position);
this.elements.push(element);
}
}

module.exports = Room;
5 changes: 5 additions & 0 deletions creational/abstract-factory/maze/Wall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Wall {

}

module.exports = Wall;
9 changes: 9 additions & 0 deletions creational/abstract-factory/maze/bombed/BombedDoor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Door = require ('../Door');

class BombedDoor extends Door {
constructor(room1, room2) {
super(room1, room2);
}
}

module.exports = BombedDoor;
9 changes: 9 additions & 0 deletions creational/abstract-factory/maze/bombed/BombedMaze.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Maze = require ('../Maze');

class BombedMaze extends Maze {
constructor() {
super();
}
}

module.exports = BombedMaze;
30 changes: 30 additions & 0 deletions creational/abstract-factory/maze/bombed/BombedMazeFactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const MazeFactory = require ('../MazeFactory');

const Door = require('./BombedDoor');
const Room = require('./BombedRoom');
const Maze = require('./BombedMaze');
const Wall = require('./BombedWall');

class BombedMazeFactory extends MazeFactory {
constructor() {
super();
}

makeMaze() {
return new Maze();
}

makeDoor(room1, room2) {
return new Door(room1, room2);
}

makeRoom(roomNumber) {
return new Room(roomNumber);
}

makeWall() {
return new Wall();
}
}

module.exports = BombedMazeFactory;
9 changes: 9 additions & 0 deletions creational/abstract-factory/maze/bombed/BombedRoom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Room = require ('../Room');

class BombedRoom extends Room {
constructor(roomNumber) {
super(roomNumber);
}
}

module.exports = BombedRoom;
9 changes: 9 additions & 0 deletions creational/abstract-factory/maze/bombed/BombedWall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Wall = require ('../Wall');

class BombedWall extends Wall {
constructor() {
super();
}
}

module.exports = BombedWall;
9 changes: 9 additions & 0 deletions creational/abstract-factory/maze/enchanted/EnchantedDoor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Door = require ('../Door');

class EnchantedDoor extends Door {
constructor(room1, room2) {
super(room1, room2);
}
}

module.exports = EnchantedDoor;
9 changes: 9 additions & 0 deletions creational/abstract-factory/maze/enchanted/EnchantedMaze.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Maze = require ('../Maze');

class EnchantedMaze extends Maze {
constructor() {
super();
}
}

module.exports = EnchantedMaze;
30 changes: 30 additions & 0 deletions creational/abstract-factory/maze/enchanted/EnchantedMazeFactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const MazeFactory = require ('../MazeFactory');

const Door = require('./EnchantedDoor');
const Room = require('./EnchantedRoom');
const Maze = require('./EnchantedMaze');
const Wall = require('./EnchantedWall');

class EnchantedMazeFactory extends MazeFactory {
constructor() {
super();
}

makeMaze() {
return new Maze();
}

makeDoor(room1, room2) {
return new Door(room1, room2);
}

makeRoom(roomNumber) {
return new Room(roomNumber);
}

makeWall() {
return new Wall();
}
}

module.exports = EnchantedMazeFactory;
9 changes: 9 additions & 0 deletions creational/abstract-factory/maze/enchanted/EnchantedRoom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Room = require ('../Room');

class EnchantedRoom extends Room {
constructor(roomNumber) {
super(roomNumber);
}
}

module.exports = EnchantedRoom;
9 changes: 9 additions & 0 deletions creational/abstract-factory/maze/enchanted/EnchantedWall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Wall = require ('../Wall');

class EnchantedWall extends Wall {
constructor() {
super();
}
}

module.exports = EnchantedWall;
10 changes: 10 additions & 0 deletions creational/builder/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const BurgerBuilder = require ('./subway/BurgerBuilder');

const burger = (new BurgerBuilder(15))
.chooseBread('3 queijos')
.chooseCheeze('cheedar')
.addSauces(['parmesão', 'chiplote'])
.addSalads(['tomate', 'alface', 'azeitonas'])
.build();

console.log(burger);
11 changes: 11 additions & 0 deletions creational/builder/subway/Burger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Burger {
constructor(builder) {
this.size = builder.size;
this.bread = builder.bread;
this.cheeze = builder.cheeze;
this.sauces = builder.sauces || false;
this.salads = builder.salads || false;
}
}

module.exports = Burger;
34 changes: 34 additions & 0 deletions creational/builder/subway/BurgerBuilder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const Burger = require ('./Burger');

class BurgerBuilder {

constructor(size) {
this.size = size
}

chooseBread(bread) {
this.bread = bread;
return this;
}

chooseCheeze(cheeze) {
this.cheeze = cheeze;
return this;
}

addSauces(sauces = []) {
this.sauces = sauces;
return this;
}

addSalads(salads = []) {
this.salads = salads;
return this;
}

build() {
return new Burger(this);
}
}

module.exports = BurgerBuilder;
12 changes: 12 additions & 0 deletions creational/factory-method/cars/CarFactoryMethod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CarFactoryMethod {
constructor () {
this.cheap = 'cheap';
this.fast = 'fast';
}

create (type) {
return this.makeCar(type);
}
}

module.exports = CarFactoryMethod;
33 changes: 33 additions & 0 deletions creational/factory-method/cars/Cars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class Mercedes {
set color (color) {
this.myColor = color;
}

get color () {
return this.myColor;
}

addAMGTunning() {}
}

class Ferrari {
set color (color) {
this.myColor = color;
}

get color () {
return this.myColor;
}
}

class Beetle {
set color (color) {
this.myColor = color;
}

get color () {
return this.myColor;
}
}

module.exports = {Mercedes, Ferrari, Beetle};
Loading

0 comments on commit f6f8c93

Please sign in to comment.