├── .gitignore ├── GoF ├── classic │ ├── Behavioral │ │ ├── ChainOfResponsibility │ │ │ ├── ChainOfResponsibility.dia │ │ │ ├── ChainOfResponsibility.png │ │ │ ├── CoffeeScript │ │ │ │ ├── API │ │ │ │ │ ├── Racer.coffee │ │ │ │ │ ├── Runner.coffee │ │ │ │ │ ├── Swimmer.coffee │ │ │ │ │ └── Walker.coffee │ │ │ │ └── client.coffee │ │ │ ├── ECMAScript │ │ │ │ ├── ES5 │ │ │ │ │ ├── API │ │ │ │ │ │ ├── Racer.js │ │ │ │ │ │ ├── Runner.js │ │ │ │ │ │ ├── Swimmer.js │ │ │ │ │ │ └── Walker.js │ │ │ │ │ └── client.js │ │ │ │ └── ES6 │ │ │ │ │ ├── API │ │ │ │ │ ├── Racer.js │ │ │ │ │ ├── Runner.js │ │ │ │ │ ├── Swimmer.js │ │ │ │ │ └── Walker.js │ │ │ │ │ └── client.js │ │ │ ├── README.md │ │ │ └── TypeScript │ │ │ │ ├── API │ │ │ │ ├── Racer.ts │ │ │ │ ├── Runner.ts │ │ │ │ ├── Swimmer.ts │ │ │ │ └── Walker.ts │ │ │ │ └── client.ts │ │ ├── Command │ │ │ ├── CoffeeScript │ │ │ │ ├── API │ │ │ │ │ ├── Customer.coffee │ │ │ │ │ ├── Order.coffee │ │ │ │ │ ├── Restaurant.coffee │ │ │ │ │ └── TexMex.coffee │ │ │ │ └── client.coffee │ │ │ ├── Command.dia │ │ │ ├── Command.png │ │ │ ├── ECMAScript │ │ │ │ ├── ES5 │ │ │ │ │ ├── API │ │ │ │ │ │ ├── Customer.js │ │ │ │ │ │ ├── Order.js │ │ │ │ │ │ ├── Restaurant.js │ │ │ │ │ │ └── TexMex.js │ │ │ │ │ └── client.js │ │ │ │ └── ES6 │ │ │ │ │ ├── API │ │ │ │ │ ├── Customer.js │ │ │ │ │ ├── Order.js │ │ │ │ │ ├── Restaurant.js │ │ │ │ │ └── TexMex.js │ │ │ │ │ └── client.js │ │ │ ├── README.md │ │ │ └── TypeScript │ │ │ │ ├── API │ │ │ │ ├── Customer.ts │ │ │ │ ├── Order.ts │ │ │ │ ├── Restaurant.ts │ │ │ │ └── TexMex.ts │ │ │ │ └── client.ts │ │ ├── Interpreter │ │ │ ├── CoffeeScript │ │ │ │ ├── API │ │ │ │ │ ├── Arpeggio.coffee │ │ │ │ │ ├── MusicNotation.coffee │ │ │ │ │ ├── Note.coffee │ │ │ │ │ └── Sonata.coffee │ │ │ │ └── client.coffee │ │ │ ├── ECMAScript │ │ │ │ ├── ES5 │ │ │ │ │ ├── API │ │ │ │ │ │ ├── Arpeggio.js │ │ │ │ │ │ ├── MusicNotation.js │ │ │ │ │ │ ├── Note.js │ │ │ │ │ │ └── Sonata.js │ │ │ │ │ └── client.js │ │ │ │ └── ES6 │ │ │ │ │ ├── API │ │ │ │ │ ├── Arpeggio.js │ │ │ │ │ ├── MusicNotation.js │ │ │ │ │ ├── Note.js │ │ │ │ │ └── Sonata.js │ │ │ │ │ └── client.js │ │ │ ├── Interpreter.dia │ │ │ ├── Interpreter.png │ │ │ ├── README.md │ │ │ └── TypeScript │ │ │ │ ├── API │ │ │ │ ├── Arpeggio.ts │ │ │ │ ├── MusicNotation.ts │ │ │ │ ├── Note.ts │ │ │ │ └── Sonata.ts │ │ │ │ └── client.ts │ │ ├── Iterator │ │ │ ├── CoffeeScript │ │ │ │ ├── API │ │ │ │ │ ├── Catalog.coffee │ │ │ │ │ ├── Collection.coffee │ │ │ │ │ ├── Library.coffee │ │ │ │ │ └── LibraryCatalog.coffee │ │ │ │ └── client.coffee │ │ │ ├── ECMAScript │ │ │ │ ├── ES5 │ │ │ │ │ ├── API │ │ │ │ │ │ ├── Catalog.js │ │ │ │ │ │ ├── Collection.js │ │ │ │ │ │ ├── Library.js │ │ │ │ │ │ └── LibraryCatalog.js │ │ │ │ │ └── client.js │ │ │ │ └── ES6 │ │ │ │ │ ├── API │ │ │ │ │ ├── Catalog.js │ │ │ │ │ ├── Collection.js │ │ │ │ │ ├── Library.js │ │ │ │ │ └── LibraryCatalog.js │ │ │ │ │ └── client.js │ │ │ ├── Iterator.dia │ │ │ ├── Iterator.png │ │ │ ├── README.md │ │ │ └── TypeScript │ │ │ │ ├── API │ │ │ │ ├── Catalog.ts │ │ │ │ ├── Collection.ts │ │ │ │ ├── Library.ts │ │ │ │ └── LibraryCatalog.ts │ │ │ │ └── client.ts │ │ ├── Mediator │ │ │ ├── CoffeeScript │ │ │ │ ├── API │ │ │ │ │ ├── Dick.coffee │ │ │ │ │ ├── Harry.coffee │ │ │ │ │ ├── Mediator.coffee │ │ │ │ │ ├── Neighbor.coffee │ │ │ │ │ └── Tom.coffee │ │ │ │ └── client.coffee │ │ │ ├── ECMAScript │ │ │ │ ├── ES5 │ │ │ │ │ ├── API │ │ │ │ │ │ ├── Dick.js │ │ │ │ │ │ ├── Harry.js │ │ │ │ │ │ ├── Mediator.js │ │ │ │ │ │ ├── Neighbor.js │ │ │ │ │ │ └── Tom.js │ │ │ │ │ └── client.js │ │ │ │ └── ES6 │ │ │ │ │ ├── API │ │ │ │ │ ├── Dick.js │ │ │ │ │ ├── Harry.js │ │ │ │ │ ├── Mediator.js │ │ │ │ │ ├── Neighbor.js │ │ │ │ │ └── Tom.js │ │ │ │ │ └── client.js │ │ │ ├── Mediator.dia │ │ │ ├── Mediator.png │ │ │ ├── README.md │ │ │ └── TypeScript │ │ │ │ ├── API │ │ │ │ ├── Dick.ts │ │ │ │ ├── Harry.ts │ │ │ │ ├── Mediator.ts │ │ │ │ ├── Neighbor.ts │ │ │ │ └── Tom.ts │ │ │ │ └── client.ts │ │ ├── Memento │ │ │ ├── CoffeeScript │ │ │ │ ├── API │ │ │ │ │ ├── Bookmark.coffee │ │ │ │ │ ├── BookmarksManager.coffee │ │ │ │ │ └── Browser.coffee │ │ │ │ └── client.coffee │ │ │ ├── ECMAScript │ │ │ │ ├── ES5 │ │ │ │ │ ├── API │ │ │ │ │ │ ├── Bookmark.js │ │ │ │ │ │ ├── BookmarksManager.js │ │ │ │ │ │ └── Browser.js │ │ │ │ │ └── client.js │ │ │ │ └── ES6 │ │ │ │ │ ├── API │ │ │ │ │ ├── Bookmark.js │ │ │ │ │ ├── BookmarksManager.js │ │ │ │ │ └── Browser.js │ │ │ │ │ └── client.js │ │ │ ├── Memento.dia │ │ │ ├── Memento.png │ │ │ ├── README.md │ │ │ └── TypeScript │ │ │ │ ├── API │ │ │ │ ├── Bookmark.ts │ │ │ │ ├── BookmarksManager.ts │ │ │ │ └── Browser.ts │ │ │ │ └── client.ts │ │ ├── Observer │ │ │ ├── CoffeeScript │ │ │ │ ├── API │ │ │ │ │ ├── Crocodile.coffee │ │ │ │ │ ├── Gazelle.coffee │ │ │ │ │ ├── Lion.coffee │ │ │ │ │ ├── Predator.coffee │ │ │ │ │ └── Prey.coffee │ │ │ │ └── client.coffee │ │ │ ├── ECMAScript │ │ │ │ ├── ES5 │ │ │ │ │ ├── API │ │ │ │ │ │ ├── Crocodile.js │ │ │ │ │ │ ├── Gazelle.js │ │ │ │ │ │ ├── Lion.js │ │ │ │ │ │ ├── Predator.js │ │ │ │ │ │ └── Prey.js │ │ │ │ │ └── client.js │ │ │ │ └── ES6 │ │ │ │ │ ├── API │ │ │ │ │ ├── Crocodile.js │ │ │ │ │ ├── Gazelle.js │ │ │ │ │ ├── Lion.js │ │ │ │ │ ├── Predator.js │ │ │ │ │ └── Prey.js │ │ │ │ │ └── client.js │ │ │ ├── Observer.dia │ │ │ ├── Observer.png │ │ │ ├── README.md │ │ │ └── TypeScript │ │ │ │ ├── API │ │ │ │ ├── Crocodile.ts │ │ │ │ ├── Gazelle.ts │ │ │ │ ├── Lion.ts │ │ │ │ ├── Predator.ts │ │ │ │ └── Prey.ts │ │ │ │ └── client.ts │ │ ├── State │ │ │ ├── CoffeeScript │ │ │ │ ├── API │ │ │ │ │ ├── Computer.coffee │ │ │ │ │ ├── ComputerState.coffee │ │ │ │ │ ├── Off.coffee │ │ │ │ │ └── On.coffee │ │ │ │ └── client.coffee │ │ │ ├── ECMAScript │ │ │ │ ├── ES5 │ │ │ │ │ ├── API │ │ │ │ │ │ ├── Computer.js │ │ │ │ │ │ ├── ComputerState.js │ │ │ │ │ │ ├── Off.js │ │ │ │ │ │ └── On.js │ │ │ │ │ └── client.js │ │ │ │ └── ES6 │ │ │ │ │ ├── API │ │ │ │ │ ├── Computer.js │ │ │ │ │ ├── ComputerState.js │ │ │ │ │ ├── Off.js │ │ │ │ │ └── On.js │ │ │ │ │ └── client.js │ │ │ ├── README.md │ │ │ ├── State.dia │ │ │ ├── State.png │ │ │ └── TypeScript │ │ │ │ ├── API │ │ │ │ ├── Computer.ts │ │ │ │ ├── ComputerState.ts │ │ │ │ ├── Off.ts │ │ │ │ └── On.ts │ │ │ │ └── client.ts │ │ ├── Strategy │ │ │ ├── CoffeeScript │ │ │ │ ├── API │ │ │ │ │ ├── Defense.coffee │ │ │ │ │ ├── FightingGame.coffee │ │ │ │ │ ├── Offense.coffee │ │ │ │ │ └── Strategy.coffee │ │ │ │ └── client.coffee │ │ │ ├── ECMAScript │ │ │ │ ├── ES5 │ │ │ │ │ ├── API │ │ │ │ │ │ ├── Defense.js │ │ │ │ │ │ ├── FightingGame.js │ │ │ │ │ │ ├── Offense.js │ │ │ │ │ │ └── Strategy.js │ │ │ │ │ └── client.js │ │ │ │ └── ES6 │ │ │ │ │ ├── API │ │ │ │ │ ├── Defense.js │ │ │ │ │ ├── FightingGame.js │ │ │ │ │ ├── Offense.js │ │ │ │ │ └── Strategy.js │ │ │ │ │ └── client.js │ │ │ ├── README.md │ │ │ ├── Strategy.dia │ │ │ ├── Strategy.png │ │ │ └── TypeScript │ │ │ │ ├── API │ │ │ │ ├── Defense.ts │ │ │ │ ├── FightingGame.ts │ │ │ │ ├── Offense.ts │ │ │ │ └── Strategy.ts │ │ │ │ └── client.ts │ │ ├── Template │ │ │ ├── CoffeeScript │ │ │ │ ├── API │ │ │ │ │ ├── Building.coffee │ │ │ │ │ ├── Home.coffee │ │ │ │ │ └── House.coffee │ │ │ │ └── client.coffee │ │ │ ├── ECMAScript │ │ │ │ ├── ES5 │ │ │ │ │ ├── API │ │ │ │ │ │ ├── Building.js │ │ │ │ │ │ ├── Home.js │ │ │ │ │ │ └── House.js │ │ │ │ │ └── client.js │ │ │ │ └── ES6 │ │ │ │ │ ├── API │ │ │ │ │ ├── Building.js │ │ │ │ │ ├── Home.js │ │ │ │ │ └── House.js │ │ │ │ │ └── client.js │ │ │ ├── README.md │ │ │ ├── Template.dia │ │ │ ├── Template.png │ │ │ └── TypeScript │ │ │ │ ├── API │ │ │ │ ├── Building.ts │ │ │ │ ├── Home.ts │ │ │ │ └── House.ts │ │ │ │ └── client.ts │ │ └── Visitor │ │ │ ├── CoffeeScript │ │ │ ├── API │ │ │ │ ├── Abbey.coffee │ │ │ │ ├── Castle.coffee │ │ │ │ ├── HistoricalMonument.coffee │ │ │ │ ├── Tourist.coffee │ │ │ │ └── Visitor.coffee │ │ │ └── client.coffee │ │ │ ├── ECMAScript │ │ │ ├── ES5 │ │ │ │ ├── API │ │ │ │ │ ├── Abbey.js │ │ │ │ │ ├── Castle.js │ │ │ │ │ ├── HistoricalMonument.js │ │ │ │ │ ├── Tourist.js │ │ │ │ │ └── Visitor.js │ │ │ │ └── client.js │ │ │ └── ES6 │ │ │ │ ├── API │ │ │ │ ├── Abbey.js │ │ │ │ ├── Castle.js │ │ │ │ ├── HistoricalMonument.js │ │ │ │ ├── Tourist.js │ │ │ │ └── Visitor.js │ │ │ │ └── client.js │ │ │ ├── README.md │ │ │ ├── TypeScript │ │ │ ├── API │ │ │ │ ├── Abbey.ts │ │ │ │ ├── Castle.ts │ │ │ │ ├── HistoricalMonument.ts │ │ │ │ ├── Tourist.ts │ │ │ │ └── Visitor.ts │ │ │ └── client.ts │ │ │ ├── Visitor.dia │ │ │ └── Visitor.png │ ├── Creational │ │ ├── AbstractFactory │ │ │ ├── AbstractFactory.dia │ │ │ ├── AbstractFactory.png │ │ │ ├── CoffeeScript │ │ │ │ ├── API │ │ │ │ │ ├── Debian.coffee │ │ │ │ │ ├── FactoryOfFactories.coffee │ │ │ │ │ ├── LinuxDistro.coffee │ │ │ │ │ ├── LinuxFactory.coffee │ │ │ │ │ ├── MacFactory.coffee │ │ │ │ │ ├── MacRelease.coffee │ │ │ │ │ ├── OS9.coffee │ │ │ │ │ ├── OSFactory.coffee │ │ │ │ │ ├── OSX.coffee │ │ │ │ │ ├── RedHat.coffee │ │ │ │ │ ├── Vista.coffee │ │ │ │ │ ├── WindowsFactory.coffee │ │ │ │ │ ├── WindowsVersion.coffee │ │ │ │ │ └── XP.coffee │ │ │ │ └── client.coffee │ │ │ ├── ECMAScript │ │ │ │ ├── ES5 │ │ │ │ │ ├── API │ │ │ │ │ │ ├── Debian.js │ │ │ │ │ │ ├── FactoryOfFactories.js │ │ │ │ │ │ ├── LinuxDistro.js │ │ │ │ │ │ ├── LinuxFactory.js │ │ │ │ │ │ ├── MacFactory.js │ │ │ │ │ │ ├── MacRelease.js │ │ │ │ │ │ ├── OS9.js │ │ │ │ │ │ ├── OSFactory.js │ │ │ │ │ │ ├── OSX.js │ │ │ │ │ │ ├── RedHat.js │ │ │ │ │ │ ├── Vista.js │ │ │ │ │ │ ├── WindowsFactory.js │ │ │ │ │ │ ├── WindowsVersion.js │ │ │ │ │ │ └── XP.js │ │ │ │ │ └── client.js │ │ │ │ └── ES6 │ │ │ │ │ ├── API │ │ │ │ │ ├── Debian.js │ │ │ │ │ ├── FactoryOfFactories.js │ │ │ │ │ ├── LinuxDistro.js │ │ │ │ │ ├── LinuxFactory.js │ │ │ │ │ ├── MacFactory.js │ │ │ │ │ ├── MacRelease.js │ │ │ │ │ ├── OS9.js │ │ │ │ │ ├── OSFactory.js │ │ │ │ │ ├── OSX.js │ │ │ │ │ ├── RedHat.js │ │ │ │ │ ├── Vista.js │ │ │ │ │ ├── WindowsFactory.js │ │ │ │ │ ├── WindowsVersion.js │ │ │ │ │ └── XP.js │ │ │ │ │ └── client.js │ │ │ ├── README.md │ │ │ └── TypeScript │ │ │ │ ├── API │ │ │ │ ├── Debian.ts │ │ │ │ ├── FactoryOfFactories.ts │ │ │ │ ├── LinuxDistro.ts │ │ │ │ ├── LinuxFactory.ts │ │ │ │ ├── MacFactory.ts │ │ │ │ ├── MacRelease.ts │ │ │ │ ├── OS9.ts │ │ │ │ ├── OSFactory.ts │ │ │ │ ├── OSX.ts │ │ │ │ ├── RedHat.ts │ │ │ │ ├── Vista.ts │ │ │ │ ├── WindowsFactory.ts │ │ │ │ ├── WindowsVersion.ts │ │ │ │ └── XP.ts │ │ │ │ └── client.ts │ │ ├── Builder │ │ │ ├── Builder.dia │ │ │ ├── Builder.png │ │ │ ├── CoffeeScript │ │ │ │ ├── API │ │ │ │ │ ├── Geek.coffee │ │ │ │ │ ├── Manufacturer.coffee │ │ │ │ │ ├── PC.coffee │ │ │ │ │ └── Workforce.coffee │ │ │ │ └── client.coffee │ │ │ ├── ECMAScript │ │ │ │ ├── ES5 │ │ │ │ │ ├── API │ │ │ │ │ │ ├── Geek.js │ │ │ │ │ │ ├── Manufacturer.js │ │ │ │ │ │ ├── PC.js │ │ │ │ │ │ └── Workforce.js │ │ │ │ │ └── client.js │ │ │ │ └── ES6 │ │ │ │ │ ├── API │ │ │ │ │ ├── Geek.js │ │ │ │ │ ├── Manufacturer.js │ │ │ │ │ ├── PC.js │ │ │ │ │ └── Workforce.js │ │ │ │ │ └── client.js │ │ │ ├── README.md │ │ │ └── TypeScript │ │ │ │ ├── API │ │ │ │ ├── Geek.ts │ │ │ │ ├── Manufacturer.ts │ │ │ │ ├── PC.ts │ │ │ │ └── Workforce.ts │ │ │ │ └── client.ts │ │ ├── Factory │ │ │ ├── CoffeeScript │ │ │ │ ├── API │ │ │ │ │ ├── Debian.coffee │ │ │ │ │ ├── LinuxDistro.coffee │ │ │ │ │ ├── LinuxDistrosFactory.coffee │ │ │ │ │ ├── RedHat.coffee │ │ │ │ │ └── Slackware.coffee │ │ │ │ └── client.coffee │ │ │ ├── ECMAScript │ │ │ │ ├── ES5 │ │ │ │ │ ├── API │ │ │ │ │ │ ├── Debian.js │ │ │ │ │ │ ├── LinuxDistro.js │ │ │ │ │ │ ├── LinuxDistrosFactory.js │ │ │ │ │ │ ├── RedHat.js │ │ │ │ │ │ └── Slackware.js │ │ │ │ │ └── client.js │ │ │ │ └── ES6 │ │ │ │ │ ├── API │ │ │ │ │ ├── Debian.js │ │ │ │ │ ├── LinuxDistro.js │ │ │ │ │ ├── LinuxDistrosFactory.js │ │ │ │ │ ├── RedHat.js │ │ │ │ │ └── Slackware.js │ │ │ │ │ └── client.js │ │ │ ├── Factory.dia │ │ │ ├── Factory.png │ │ │ ├── README.md │ │ │ └── TypeScript │ │ │ │ ├── API │ │ │ │ ├── Debian.ts │ │ │ │ ├── LinuxDistro.ts │ │ │ │ ├── LinuxDistrosFactory.ts │ │ │ │ ├── RedHat.ts │ │ │ │ └── Slackware.ts │ │ │ │ └── client.ts │ │ ├── Prototype │ │ │ ├── CoffeeScript │ │ │ │ ├── API │ │ │ │ │ ├── Invoice.coffee │ │ │ │ │ └── PaperSheet.coffee │ │ │ │ └── client.coffee │ │ │ ├── ECMAScript │ │ │ │ ├── ES5 │ │ │ │ │ ├── API │ │ │ │ │ │ ├── Invoice.js │ │ │ │ │ │ └── PaperSheet.js │ │ │ │ │ └── client.js │ │ │ │ └── ES6 │ │ │ │ │ ├── API │ │ │ │ │ ├── Invoice.js │ │ │ │ │ └── PaperSheet.js │ │ │ │ │ └── client.js │ │ │ ├── Prototype.dia │ │ │ ├── Prototype.png │ │ │ ├── README.md │ │ │ └── TypeScript │ │ │ │ ├── API │ │ │ │ ├── Invoice.ts │ │ │ │ └── PaperSheet.ts │ │ │ │ └── client.ts │ │ └── Singleton │ │ │ ├── CoffeeScript │ │ │ ├── API │ │ │ │ └── Me.coffee │ │ │ └── client.coffee │ │ │ ├── ECMAScript │ │ │ ├── ES5 │ │ │ │ ├── API │ │ │ │ │ └── Me.js │ │ │ │ └── client.js │ │ │ └── ES6 │ │ │ │ ├── API │ │ │ │ └── Me.js │ │ │ │ └── client.js │ │ │ ├── README.md │ │ │ ├── Singleton.dia │ │ │ ├── Singleton.png │ │ │ └── TypeScript │ │ │ ├── API │ │ │ └── Me.ts │ │ │ └── client.ts │ └── Structural │ │ ├── Adapter │ │ ├── Adapter.dia │ │ ├── Adapter.png │ │ ├── CoffeeScript │ │ │ ├── API │ │ │ │ ├── AnalogInterface.coffee │ │ │ │ ├── DigitalInterface.coffee │ │ │ │ ├── HDMIToVGAAdapter.coffee │ │ │ │ └── VGA.coffee │ │ │ └── client.coffee │ │ ├── ECMAScript │ │ │ ├── ES5 │ │ │ │ ├── API │ │ │ │ │ ├── AnalogInterface.js │ │ │ │ │ ├── DigitalInterface.js │ │ │ │ │ ├── HDMIToVGAAdapter.js │ │ │ │ │ └── VGA.js │ │ │ │ └── client.js │ │ │ └── ES6 │ │ │ │ ├── API │ │ │ │ ├── AnalogInterface.js │ │ │ │ ├── DigitalInterface.js │ │ │ │ ├── HDMIToVGAAdapter.js │ │ │ │ └── VGA.js │ │ │ │ └── client.js │ │ ├── README.md │ │ └── TypeScript │ │ │ ├── API │ │ │ ├── AnalogInterface.ts │ │ │ ├── DigitalInterface.ts │ │ │ ├── HDMIToVGAAdapter.ts │ │ │ └── VGA.ts │ │ │ └── client.ts │ │ ├── Bridge │ │ ├── Bridge.dia │ │ ├── Bridge.png │ │ ├── CoffeeScript │ │ │ ├── API │ │ │ │ ├── Carbonara.coffee │ │ │ │ ├── Pasta.coffee │ │ │ │ ├── Pesto.coffee │ │ │ │ ├── Recipe.coffee │ │ │ │ ├── Risotto.coffee │ │ │ │ └── Sauce.coffee │ │ │ └── client.coffee │ │ ├── ECMAScript │ │ │ ├── ES5 │ │ │ │ ├── API │ │ │ │ │ ├── Carbonara.js │ │ │ │ │ ├── Pasta.js │ │ │ │ │ ├── Pesto.js │ │ │ │ │ ├── Recipe.js │ │ │ │ │ ├── Risotto.js │ │ │ │ │ └── Sauce.js │ │ │ │ └── client.js │ │ │ └── ES6 │ │ │ │ ├── API │ │ │ │ ├── Carbonara.js │ │ │ │ ├── Pasta.js │ │ │ │ ├── Pesto.js │ │ │ │ ├── Recipe.js │ │ │ │ ├── Risotto.js │ │ │ │ └── Sauce.js │ │ │ │ └── client.js │ │ ├── README.md │ │ └── TypeScript │ │ │ ├── API │ │ │ ├── Carbonara.ts │ │ │ ├── Pasta.ts │ │ │ ├── Pesto.ts │ │ │ ├── Recipe.ts │ │ │ ├── Risotto.ts │ │ │ └── Sauce.ts │ │ │ └── client.ts │ │ ├── Composite │ │ ├── CoffeeScript │ │ │ ├── API │ │ │ │ ├── Ball.coffee │ │ │ │ ├── Toy.coffee │ │ │ │ └── ToyBox.coffee │ │ │ └── client.coffee │ │ ├── Composite.dia │ │ ├── Composite.png │ │ ├── ECMAScript │ │ │ ├── ES5 │ │ │ │ ├── API │ │ │ │ │ ├── Ball.js │ │ │ │ │ ├── Toy.js │ │ │ │ │ └── ToyBox.js │ │ │ │ └── client.js │ │ │ └── ES6 │ │ │ │ ├── API │ │ │ │ ├── Ball.js │ │ │ │ ├── Toy.js │ │ │ │ └── ToyBox.js │ │ │ │ └── client.js │ │ ├── README.md │ │ └── TypeScript │ │ │ ├── API │ │ │ ├── Ball.ts │ │ │ ├── Toy.ts │ │ │ └── ToyBox.ts │ │ │ └── client.ts │ │ ├── Decorator │ │ ├── CoffeeScript │ │ │ ├── API │ │ │ │ ├── Bacon.coffee │ │ │ │ ├── CustomPizza.coffee │ │ │ │ ├── Margherita.coffee │ │ │ │ ├── Peppers.coffee │ │ │ │ └── Pizza.coffee │ │ │ └── client.coffee │ │ ├── Decorator.dia │ │ ├── Decorator.png │ │ ├── ECMAScript │ │ │ ├── ES5 │ │ │ │ ├── API │ │ │ │ │ ├── Bacon.js │ │ │ │ │ ├── CustomPizza.js │ │ │ │ │ ├── Margherita.js │ │ │ │ │ ├── Peppers.js │ │ │ │ │ └── Pizza.js │ │ │ │ └── client.js │ │ │ └── ES6 │ │ │ │ ├── API │ │ │ │ ├── Bacon.js │ │ │ │ ├── CustomPizza.js │ │ │ │ ├── Margherita.js │ │ │ │ ├── Peppers.js │ │ │ │ └── Pizza.js │ │ │ │ └── client.js │ │ ├── README.md │ │ └── TypeScript │ │ │ ├── API │ │ │ ├── Bacon.ts │ │ │ ├── CustomPizza.ts │ │ │ ├── Margherita.ts │ │ │ ├── Peppers.ts │ │ │ └── Pizza.ts │ │ │ └── client.ts │ │ ├── Facade │ │ ├── CoffeeScript │ │ │ ├── API │ │ │ │ ├── Animal.coffee │ │ │ │ ├── Dog.coffee │ │ │ │ ├── HowToFeedAnimals.coffee │ │ │ │ └── Rabbit.coffee │ │ │ └── client.coffee │ │ ├── ECMAScript │ │ │ ├── ES5 │ │ │ │ ├── API │ │ │ │ │ ├── Animal.js │ │ │ │ │ ├── Dog.js │ │ │ │ │ ├── HowToFeedAnimals.js │ │ │ │ │ └── Rabbit.js │ │ │ │ └── client.js │ │ │ └── ES6 │ │ │ │ ├── API │ │ │ │ ├── Animal.js │ │ │ │ ├── Dog.js │ │ │ │ ├── HowToFeedAnimals.js │ │ │ │ └── Rabbit.js │ │ │ │ └── client.js │ │ ├── Facade.dia │ │ ├── Facade.png │ │ ├── README.md │ │ └── TypeScript │ │ │ ├── API │ │ │ ├── Animal.ts │ │ │ ├── Dog.ts │ │ │ ├── HowToFeedAnimals.ts │ │ │ └── Rabbit.ts │ │ │ └── client.ts │ │ ├── Flyweight │ │ ├── CoffeeScript │ │ │ ├── API │ │ │ │ ├── Debian.coffee │ │ │ │ ├── LinuxDistro.coffee │ │ │ │ ├── LinuxDistrosFactory.coffee │ │ │ │ ├── RedHat.coffee │ │ │ │ └── Slackware.coffee │ │ │ └── client.coffee │ │ ├── ECMAScript │ │ │ ├── ES5 │ │ │ │ ├── API │ │ │ │ │ ├── Debian.js │ │ │ │ │ ├── LinuxDistro.js │ │ │ │ │ ├── LinuxDistrosFactory.js │ │ │ │ │ ├── RedHat.js │ │ │ │ │ └── Slackware.js │ │ │ │ └── client.js │ │ │ └── ES6 │ │ │ │ ├── API │ │ │ │ ├── Debian.js │ │ │ │ ├── LinuxDistro.js │ │ │ │ ├── LinuxDistrosFactory.js │ │ │ │ ├── RedHat.js │ │ │ │ └── Slackware.js │ │ │ │ └── client.js │ │ ├── Flyweight.dia │ │ ├── Flyweight.png │ │ ├── README.md │ │ └── TypeScript │ │ │ ├── API │ │ │ ├── Debian.ts │ │ │ ├── LinuxDistro.ts │ │ │ ├── LinuxDistrosFactory.ts │ │ │ ├── RedHat.ts │ │ │ └── Slackware.ts │ │ │ └── client.ts │ │ └── Proxy │ │ ├── CoffeeScript │ │ ├── API │ │ │ ├── ATM.coffee │ │ │ ├── BankAccount.coffee │ │ │ └── FinancialEntity.coffee │ │ └── client.coffee │ │ ├── ECMAScript │ │ ├── ES5 │ │ │ ├── API │ │ │ │ ├── ATM.js │ │ │ │ ├── BankAccount.js │ │ │ │ └── FinancialEntity.js │ │ │ └── client.js │ │ └── ES6 │ │ │ ├── API │ │ │ ├── ATM.js │ │ │ ├── BankAccount.js │ │ │ └── FinancialEntity.js │ │ │ └── client.js │ │ ├── Proxy.dia │ │ ├── Proxy.png │ │ ├── README.md │ │ └── TypeScript │ │ ├── API │ │ ├── ATM.ts │ │ ├── BankAccount.ts │ │ └── FinancialEntity.ts │ │ └── client.ts └── idiomatic │ ├── Behavioral │ ├── ChainOfResponsibility │ │ ├── ChainOfResponsibility.dia │ │ ├── ChainOfResponsibility.png │ │ ├── CoffeeScript │ │ │ ├── API │ │ │ │ └── race.coffee │ │ │ └── client.coffee │ │ ├── ECMAScript │ │ │ ├── ES5 │ │ │ │ ├── API │ │ │ │ │ └── race.js │ │ │ │ └── client.js │ │ │ └── ES6 │ │ │ │ ├── API │ │ │ │ └── race.js │ │ │ │ └── client.js │ │ ├── README.md │ │ └── TypeScript │ │ │ ├── API │ │ │ └── race.ts │ │ │ └── client.ts │ ├── Command │ │ ├── CoffeeScript │ │ │ ├── API │ │ │ │ ├── customer.coffee │ │ │ │ ├── order.coffee │ │ │ │ └── restaurant.coffee │ │ │ └── client.coffee │ │ ├── Command.dia │ │ ├── Command.png │ │ ├── ECMAScript │ │ │ ├── ES5 │ │ │ │ ├── API │ │ │ │ │ ├── customer.js │ │ │ │ │ ├── order.js │ │ │ │ │ └── restaurant.js │ │ │ │ └── client.js │ │ │ └── ES6 │ │ │ │ ├── API │ │ │ │ ├── customer.js │ │ │ │ ├── order.js │ │ │ │ └── restaurant.js │ │ │ │ └── client.js │ │ ├── README.md │ │ └── TypeScript │ │ │ ├── API │ │ │ ├── customer.ts │ │ │ ├── order.ts │ │ │ └── restaurant.ts │ │ │ └── client.ts │ ├── Interpreter │ │ ├── CoffeeScript │ │ │ ├── API │ │ │ │ ├── context.coffee │ │ │ │ └── expressions.coffee │ │ │ └── client.coffee │ │ ├── ECMAScript │ │ │ ├── ES5 │ │ │ │ ├── API │ │ │ │ │ ├── context.js │ │ │ │ │ └── expressions.js │ │ │ │ └── client.js │ │ │ └── ES6 │ │ │ │ ├── API │ │ │ │ ├── context.js │ │ │ │ └── expressions.js │ │ │ │ └── client.js │ │ ├── Interpreter.dia │ │ ├── Interpreter.png │ │ ├── README.md │ │ └── TypeScript │ │ │ ├── API │ │ │ ├── context.ts │ │ │ └── expressions.ts │ │ │ └── client.ts │ ├── Iterator │ │ ├── CoffeeScript │ │ │ ├── API │ │ │ │ ├── iterable.coffee │ │ │ │ └── iterator.coffee │ │ │ └── client.coffee │ │ ├── ECMAScript │ │ │ ├── ES5 │ │ │ │ ├── API │ │ │ │ │ ├── iterable.js │ │ │ │ │ └── iterator.js │ │ │ │ └── client.js │ │ │ └── ES6 │ │ │ │ ├── API │ │ │ │ ├── iterable.js │ │ │ │ └── iterator.js │ │ │ │ └── client.js │ │ ├── Iterator.dia │ │ ├── Iterator.png │ │ ├── README.md │ │ └── TypeScript │ │ │ ├── API │ │ │ ├── iterable.ts │ │ │ └── iterator.ts │ │ │ └── client.ts │ ├── Mediator │ │ ├── CoffeeScript │ │ │ ├── API │ │ │ │ ├── colleagues.coffee │ │ │ │ └── mediator.coffee │ │ │ └── client.coffee │ │ ├── ECMAScript │ │ │ ├── ES5 │ │ │ │ ├── API │ │ │ │ │ ├── colleagues.js │ │ │ │ │ └── mediator.js │ │ │ │ └── client.js │ │ │ └── ES6 │ │ │ │ ├── API │ │ │ │ ├── colleagues.js │ │ │ │ └── mediator.js │ │ │ │ └── client.js │ │ ├── Mediator.dia │ │ ├── Mediator.png │ │ ├── README.md │ │ └── TypeScript │ │ │ ├── API │ │ │ ├── colleagues.ts │ │ │ └── mediator.ts │ │ │ └── client.ts │ ├── Memento │ │ ├── CoffeeScript │ │ │ ├── API │ │ │ │ ├── bookmarks.coffee │ │ │ │ └── browser.coffee │ │ │ └── client.coffee │ │ ├── ECMAScript │ │ │ ├── ES5 │ │ │ │ ├── API │ │ │ │ │ ├── bookmarks.js │ │ │ │ │ └── browser.js │ │ │ │ └── client.js │ │ │ └── ES6 │ │ │ │ ├── API │ │ │ │ ├── bookmarks.js │ │ │ │ └── browser.js │ │ │ │ └── client.js │ │ ├── Memento.dia │ │ ├── Memento.png │ │ ├── README.md │ │ └── TypeScript │ │ │ ├── API │ │ │ ├── bookmarks.ts │ │ │ └── browser.ts │ │ │ └── client.ts │ ├── Observer │ │ ├── CoffeeScript │ │ │ ├── API │ │ │ │ ├── observable.coffee │ │ │ │ └── observers.coffee │ │ │ └── client.coffee │ │ ├── ECMAScript │ │ │ ├── ES5 │ │ │ │ ├── API │ │ │ │ │ ├── observable.js │ │ │ │ │ └── observers.js │ │ │ │ └── client.js │ │ │ └── ES6 │ │ │ │ ├── API │ │ │ │ ├── observable.js │ │ │ │ └── observers.js │ │ │ │ └── client.js │ │ ├── Observer.dia │ │ ├── Observer.png │ │ ├── README.md │ │ └── TypeScript │ │ │ ├── API │ │ │ ├── observable.ts │ │ │ └── observers.ts │ │ │ └── client.ts │ ├── State │ │ ├── CoffeeScript │ │ │ ├── API │ │ │ │ ├── context.coffee │ │ │ │ └── states.coffee │ │ │ └── client.coffee │ │ ├── ECMAScript │ │ │ ├── ES5 │ │ │ │ ├── API │ │ │ │ │ ├── context.js │ │ │ │ │ └── states.js │ │ │ │ └── client.js │ │ │ └── ES6 │ │ │ │ ├── API │ │ │ │ ├── context.js │ │ │ │ └── states.js │ │ │ │ └── client.js │ │ ├── README.md │ │ ├── State.dia │ │ ├── State.png │ │ └── TypeScript │ │ │ ├── API │ │ │ ├── context.ts │ │ │ └── states.ts │ │ │ └── client.ts │ ├── Strategy │ │ ├── CoffeeScript │ │ │ ├── API │ │ │ │ ├── context.coffee │ │ │ │ └── strategies.coffee │ │ │ └── client.coffee │ │ ├── ECMAScript │ │ │ ├── ES5 │ │ │ │ ├── API │ │ │ │ │ ├── context.js │ │ │ │ │ └── strategies.js │ │ │ │ └── client.js │ │ │ └── ES6 │ │ │ │ ├── API │ │ │ │ ├── context.js │ │ │ │ └── strategies.js │ │ │ │ └── client.js │ │ ├── README.md │ │ ├── Strategy.dia │ │ ├── Strategy.png │ │ └── TypeScript │ │ │ ├── API │ │ │ ├── context.ts │ │ │ └── strategies.ts │ │ │ └── client.ts │ ├── Template │ │ ├── CoffeeScript │ │ │ ├── API │ │ │ │ ├── homes.coffee │ │ │ │ └── template.coffee │ │ │ └── client.coffee │ │ ├── ECMAScript │ │ │ ├── ES5 │ │ │ │ ├── API │ │ │ │ │ ├── homes.js │ │ │ │ │ └── template.js │ │ │ │ └── client.js │ │ │ └── ES6 │ │ │ │ ├── API │ │ │ │ ├── homes.js │ │ │ │ └── template.js │ │ │ │ └── client.js │ │ ├── README.md │ │ ├── Template.dia │ │ ├── Template.png │ │ └── TypeScript │ │ │ ├── API │ │ │ ├── homes.ts │ │ │ └── template.ts │ │ │ └── client.ts │ └── Visitor │ │ ├── CoffeeScript │ │ ├── API │ │ │ ├── monuments.coffee │ │ │ └── visitor.coffee │ │ └── client.coffee │ │ ├── ECMAScript │ │ ├── ES5 │ │ │ ├── API │ │ │ │ ├── monuments.js │ │ │ │ └── visitor.js │ │ │ └── client.js │ │ └── ES6 │ │ │ ├── API │ │ │ ├── monuments.js │ │ │ └── visitor.js │ │ │ └── client.js │ │ ├── README.md │ │ ├── TypeScript │ │ ├── API │ │ │ ├── monuments.ts │ │ │ └── visitor.ts │ │ └── client.ts │ │ ├── Visitor.dia │ │ └── Visitor.png │ ├── Creational │ ├── AbstractFactory │ │ ├── AbstractFactory.dia │ │ ├── AbstractFactory.png │ │ ├── CoffeeScript │ │ │ ├── API │ │ │ │ └── factories.coffee │ │ │ └── client.coffee │ │ ├── ECMAScript │ │ │ ├── ES5 │ │ │ │ ├── API │ │ │ │ │ └── factories.js │ │ │ │ └── client.js │ │ │ └── ES6 │ │ │ │ ├── API │ │ │ │ └── factories.js │ │ │ │ └── client.js │ │ ├── README.md │ │ └── TypeScript │ │ │ ├── API │ │ │ └── factories.ts │ │ │ └── client.ts │ ├── Builder │ │ ├── Builder.dia │ │ ├── Builder.png │ │ ├── CoffeeScript │ │ │ ├── API │ │ │ │ ├── builder.coffee │ │ │ │ ├── manufacturer.coffee │ │ │ │ └── pc.coffee │ │ │ └── client.coffee │ │ ├── ECMAScript │ │ │ ├── ES5 │ │ │ │ ├── API │ │ │ │ │ ├── builder.js │ │ │ │ │ ├── manufacturer.js │ │ │ │ │ └── pc.js │ │ │ │ └── client.js │ │ │ └── ES6 │ │ │ │ ├── API │ │ │ │ ├── builder.js │ │ │ │ ├── manufacturer.js │ │ │ │ └── pc.js │ │ │ │ └── client.js │ │ ├── README.md │ │ └── TypeScript │ │ │ ├── API │ │ │ ├── builder.ts │ │ │ ├── manufacturer.ts │ │ │ └── pc.ts │ │ │ └── client.ts │ ├── Factory │ │ ├── CoffeeScript │ │ │ ├── API │ │ │ │ └── factory.coffee │ │ │ └── client.coffee │ │ ├── ECMAScript │ │ │ ├── ES5 │ │ │ │ ├── API │ │ │ │ │ └── factory.js │ │ │ │ └── client.js │ │ │ └── ES6 │ │ │ │ ├── API │ │ │ │ └── factory.js │ │ │ │ └── client.js │ │ ├── Factory.dia │ │ ├── Factory.png │ │ ├── README.md │ │ └── TypeScript │ │ │ ├── API │ │ │ └── factory.ts │ │ │ └── client.ts │ ├── Prototype │ │ ├── CoffeeScript │ │ │ ├── API │ │ │ │ └── photocopy.coffee │ │ │ └── client.coffee │ │ ├── ECMAScript │ │ │ ├── ES5 │ │ │ │ ├── API │ │ │ │ │ └── photocopy.js │ │ │ │ └── client.js │ │ │ └── ES6 │ │ │ │ ├── API │ │ │ │ └── photocopy.js │ │ │ │ └── client.js │ │ ├── Prototype.dia │ │ ├── Prototype.png │ │ ├── README.md │ │ └── TypeScript │ │ │ ├── API │ │ │ └── photocopy.ts │ │ │ └── client.ts │ └── Singleton │ │ ├── CoffeeScript │ │ ├── API │ │ │ └── me.coffee │ │ └── client.coffee │ │ ├── ECMAScript │ │ ├── ES5 │ │ │ ├── API │ │ │ │ └── me.js │ │ │ └── client.js │ │ └── ES6 │ │ │ ├── API │ │ │ └── me.js │ │ │ └── client.js │ │ ├── README.md │ │ ├── Singleton.dia │ │ ├── Singleton.png │ │ └── TypeScript │ │ ├── API │ │ └── me.ts │ │ └── client.ts │ └── Structural │ ├── Adapter │ ├── Adapter.dia │ ├── Adapter.png │ ├── CoffeeScript │ │ ├── API │ │ │ └── connections.coffee │ │ └── client.coffee │ ├── ECMAScript │ │ ├── ES5 │ │ │ ├── API │ │ │ │ └── connections.js │ │ │ └── client.js │ │ └── ES6 │ │ │ ├── API │ │ │ └── connections.js │ │ │ └── client.js │ ├── README.md │ └── TypeScript │ │ ├── API │ │ └── connections.ts │ │ └── client.ts │ ├── Bridge │ ├── Bridge.dia │ ├── Bridge.png │ ├── CoffeeScript │ │ ├── API │ │ │ ├── recipes.coffee │ │ │ └── sauces.coffee │ │ └── client.coffee │ ├── ECMAScript │ │ ├── ES5 │ │ │ ├── API │ │ │ │ ├── recipes.js │ │ │ │ └── sauces.js │ │ │ └── client.js │ │ └── ES6 │ │ │ ├── API │ │ │ ├── recipes.js │ │ │ └── sauces.js │ │ │ └── client.js │ ├── README.md │ └── TypeScript │ │ ├── API │ │ ├── recipes.ts │ │ └── sauces.ts │ │ └── client.ts │ ├── Composite │ ├── CoffeeScript │ │ ├── API │ │ │ └── toys.coffee │ │ └── client.coffee │ ├── Composite.dia │ ├── Composite.png │ ├── ECMAScript │ │ ├── ES5 │ │ │ ├── API │ │ │ │ └── toys.js │ │ │ └── client.js │ │ └── ES6 │ │ │ ├── API │ │ │ └── toys.js │ │ │ └── client.js │ ├── README.md │ └── TypeScript │ │ ├── API │ │ └── toys.ts │ │ └── client.ts │ ├── Decorator │ ├── CoffeeScript │ │ ├── API │ │ │ └── pizza.coffee │ │ └── Decorator.coffee │ ├── Decorator.dia │ ├── Decorator.png │ ├── ECMAScript │ │ ├── ES5 │ │ │ ├── API │ │ │ │ └── pizza.js │ │ │ └── client.js │ │ └── ES6 │ │ │ ├── API │ │ │ └── pizza.js │ │ │ └── client.js │ ├── README.md │ └── TypeScript │ │ ├── API │ │ └── pizza.ts │ │ └── client.ts │ ├── Facade │ ├── CoffeeScript │ │ ├── API │ │ │ ├── animals.coffee │ │ │ └── facade.coffee │ │ └── client.coffee │ ├── ECMAScript │ │ ├── ES5 │ │ │ ├── API │ │ │ │ ├── animals.js │ │ │ │ └── facade.js │ │ │ └── client.js │ │ └── ES6 │ │ │ ├── API │ │ │ ├── animals.js │ │ │ └── facade.js │ │ │ └── client.js │ ├── Facade.dia │ ├── Facade.png │ ├── README.md │ └── TypeScript │ │ ├── API │ │ ├── animals.ts │ │ └── facade.ts │ │ └── client.ts │ ├── Flyweight │ ├── CoffeeScript │ │ ├── API │ │ │ └── flyweight.coffee │ │ └── client.coffee │ ├── ECMAScript │ │ ├── ES5 │ │ │ ├── API │ │ │ │ └── flyweight.js │ │ │ └── client.js │ │ └── ES6 │ │ │ ├── API │ │ │ └── flyweight.js │ │ │ └── client.js │ ├── Flyweight.dia │ ├── Flyweight.png │ ├── README.md │ └── TypeScript │ │ ├── API │ │ └── flyweight.ts │ │ └── client.ts │ └── Proxy │ ├── CoffeeScript │ ├── API │ │ └── finance.coffee │ └── client.coffee │ ├── ECMAScript │ ├── ES5 │ │ ├── API │ │ │ └── finance.js │ │ └── client.js │ └── ES6 │ │ ├── API │ │ └── finance.js │ │ └── client.js │ ├── Proxy.dia │ ├── Proxy.png │ ├── README.md │ └── TypeScript │ ├── API │ └── finance.ts │ └── client.ts ├── LICENSE.md ├── README.md └── misc ├── Currying ├── CoffeeScript │ └── index.coffee ├── ECMAScript │ ├── ES5 │ │ └── index.js │ └── ES6 │ │ └── index.js ├── README.md └── TypeScript │ └── index.ts ├── MethodChaining ├── CoffeeScript │ └── index.coffee ├── ECMAScript │ ├── ES5 │ │ └── index.js │ └── ES6 │ │ └── index.js ├── README.md └── TypeScript │ └── index.ts ├── Module ├── CoffeeScript │ └── index.coffee ├── ECMAScript │ ├── ES5 │ │ └── index.js │ └── ES6 │ │ └── index.js ├── README.md └── TypeScript │ └── index.ts ├── ObjectSpecifier ├── CoffeeScript │ └── index.coffee ├── ECMAScript │ ├── ES5 │ │ └── index.js │ └── ES6 │ │ └── index.js ├── README.md └── TypeScript │ └── index.ts └── RevealingModule ├── CoffeeScript └── index.coffee ├── ECMAScript ├── ES5 │ └── index.js └── ES6 │ └── index.js ├── README.md └── TypeScript └── index.ts /.gitignore: -------------------------------------------------------------------------------- 1 | tags 2 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/ChainOfResponsibility/ChainOfResponsibility.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Behavioral/ChainOfResponsibility/ChainOfResponsibility.dia -------------------------------------------------------------------------------- /GoF/classic/Behavioral/ChainOfResponsibility/ChainOfResponsibility.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Behavioral/ChainOfResponsibility/ChainOfResponsibility.png -------------------------------------------------------------------------------- /GoF/classic/Behavioral/ChainOfResponsibility/CoffeeScript/API/Runner.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Racer = require './Racer' 4 | 5 | # ============================== 6 | # CONCRETE RACER 7 | # ============================== 8 | 9 | class Runner extends Racer 10 | go: -> 11 | "Runner: go!\n#{super}" 12 | 13 | module.exports = Runner 14 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/ChainOfResponsibility/CoffeeScript/API/Swimmer.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Racer = require './Racer' 4 | 5 | # ============================== 6 | # CONCRETE RACER 7 | # ============================== 8 | 9 | class Swimmer extends Racer 10 | go: -> 11 | "Swimmer: go!\n#{super}" 12 | 13 | module.exports = Swimmer 14 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/ChainOfResponsibility/CoffeeScript/API/Walker.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Racer = require './Racer' 4 | 5 | # ============================== 6 | # CONCRETE RACER 7 | # ============================== 8 | 9 | class Walker extends Racer 10 | go: -> 11 | "Walker: go!\n#{super}" 12 | 13 | module.exports = Walker 14 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/ChainOfResponsibility/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Walker = require './API/Walker' 4 | Runner = require './API/Runner' 5 | Swimmer = require './API/Swimmer' 6 | 7 | # ============================== 8 | # CLIENT CODE 9 | # ============================== 10 | 11 | walker = new Walker 12 | runner = new Runner 13 | swimmer = new Swimmer 14 | 15 | walker.setNextRelay runner 16 | runner.setNextRelay swimmer 17 | 18 | console.log walker.go() 19 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/ChainOfResponsibility/ECMAScript/ES6/API/Runner.js: -------------------------------------------------------------------------------- 1 | import Racer from './Racer'; 2 | 3 | // ============================== 4 | // CONCRETE RACER 5 | // ============================== 6 | 7 | export default class Runner extends Racer { 8 | go() { 9 | return `Runner: go!\n${super.go()}`; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/ChainOfResponsibility/ECMAScript/ES6/API/Swimmer.js: -------------------------------------------------------------------------------- 1 | import Racer from './Racer'; 2 | 3 | // ============================== 4 | // CONCRETE RACER 5 | // ============================== 6 | 7 | export default class Swimmer extends Racer { 8 | go() { 9 | return `Swimmer: go!\n${super.go()}`; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/ChainOfResponsibility/ECMAScript/ES6/API/Walker.js: -------------------------------------------------------------------------------- 1 | import Racer from './Racer'; 2 | 3 | // ============================== 4 | // CONCRETE RACER 5 | // ============================== 6 | 7 | export default class Walker extends Racer { 8 | go() { 9 | return `Walker: go!\n${super.go()}`; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/ChainOfResponsibility/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import Walker from './API/Walker'; 2 | import Runner from './API/Runner'; 3 | import Swimmer from './API/Swimmer'; 4 | 5 | // ============================== 6 | // CLIENT CODE 7 | // ============================== 8 | 9 | let walker = new Walker(), 10 | runner = new Runner(), 11 | swimmer = new Swimmer(); 12 | 13 | walker.setNextRelay(runner); 14 | runner.setNextRelay(swimmer); 15 | 16 | console.log(walker.go()); 17 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/ChainOfResponsibility/TypeScript/API/Runner.ts: -------------------------------------------------------------------------------- 1 | import Racer from './Racer'; 2 | 3 | // ============================== 4 | // CONCRETE RACER 5 | // ============================== 6 | 7 | export default class Runner extends Racer { 8 | public go(): string { 9 | return `Runner: go!\n${super.go()}`; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/ChainOfResponsibility/TypeScript/API/Swimmer.ts: -------------------------------------------------------------------------------- 1 | import Racer from './Racer'; 2 | 3 | // ============================== 4 | // CONCRETE RACER 5 | // ============================== 6 | 7 | export default class Swimmer extends Racer { 8 | public go(): string { 9 | return `Swimmer: go!\n${super.go()}`; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/ChainOfResponsibility/TypeScript/API/Walker.ts: -------------------------------------------------------------------------------- 1 | import Racer from './Racer'; 2 | 3 | // ============================== 4 | // CONCRETE RACER 5 | // ============================== 6 | 7 | export default class Walker extends Racer { 8 | public go(): string { 9 | return `Walker: go!\n${super.go()}`; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Command/CoffeeScript/API/Customer.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # CONCRETE CUSTOMER 5 | # ============================== 6 | 7 | class Customer 8 | pay: -> 9 | "Payment OK!\n" 10 | 11 | module.exports = Customer 12 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Command/CoffeeScript/API/Order.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # ABSTRACT ORDER 5 | # ============================== 6 | 7 | class Order 8 | constructor: -> 9 | throw new Error "You cannot instantiate an abstract class!" if @constructor is Order 10 | 11 | deliver: -> 12 | throw new Error "You cannot call an abstract method!" 13 | 14 | module.exports = Order 15 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Command/CoffeeScript/API/TexMex.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Order = require './Order' 4 | 5 | # ============================== 6 | # CONCRETE ORDER 7 | # ============================== 8 | 9 | class TexMex extends Order 10 | constructor: (@customer) -> 11 | 12 | deliver: -> 13 | @customer.pay() 14 | 15 | module.exports = TexMex 16 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Command/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Customer = require './API/Customer' 4 | TexMex = require './API/TexMex' 5 | Restaurant = require './API/Restaurant' 6 | 7 | # ============================== 8 | # CLIENT CODE 9 | # ============================== 10 | 11 | customer = new Customer 12 | order = new TexMex customer 13 | restaurant = new Restaurant 14 | 15 | restaurant.addOrder order 16 | console.log restaurant.prepareOrders() 17 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Command/Command.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Behavioral/Command/Command.dia -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Command/Command.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Behavioral/Command/Command.png -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Command/ECMAScript/ES5/API/Customer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // ============================== 4 | // CONCRETE CUSTOMER 5 | // ============================== 6 | 7 | var Customer = function () {}; 8 | 9 | Customer.prototype.pay = function () { 10 | return "Payment OK!\n"; 11 | }; 12 | 13 | module.exports = Customer; 14 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Command/ECMAScript/ES5/API/Order.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // ============================== 4 | // ABSTRACT ORDER 5 | // ============================== 6 | 7 | var Order = function() { 8 | if (this.constructor === Order) { 9 | throw new Error("You cannot instantiate an abstract class!"); 10 | } 11 | } 12 | 13 | Order.prototype.deliver = function () { 14 | throw new Error("You cannot call an abstract method!"); 15 | }; 16 | 17 | module.exports = Order; 18 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Command/ECMAScript/ES6/API/Customer.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // CONCRETE CUSTOMER 3 | // ============================== 4 | 5 | export default class Customer { 6 | pay() { 7 | return "Payment OK!\n"; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Command/ECMAScript/ES6/API/Order.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT ORDER 3 | // ============================== 4 | 5 | export default class Order { 6 | constructor() { 7 | if (new.target !== undefined) { 8 | throw new Error("You cannot instantiate an abstract class!"); 9 | } 10 | } 11 | 12 | deliver() { 13 | throw new Error("You cannot call an abstract method!"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Command/ECMAScript/ES6/API/TexMex.js: -------------------------------------------------------------------------------- 1 | import Order from './Order'; 2 | 3 | // ============================== 4 | // CONCRETE ORDER 5 | // ============================== 6 | 7 | export default class TexMex extends Order { 8 | constructor(customer) { 9 | super(); 10 | this._customer = customer; 11 | } 12 | 13 | deliver() { 14 | return this._customer.pay(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Command/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import Customer from './API/Customer'; 2 | import TexMex from './API/TexMex'; 3 | import Restaurant from './API/Restaurant'; 4 | 5 | // ============================== 6 | // CLIENT CODE 7 | // ============================== 8 | 9 | let customer = new Customer(), 10 | order = new TexMex(customer), 11 | restaurant = new Restaurant(); 12 | 13 | restaurant.addOrder(order); 14 | console.log(restaurant.prepareOrders()); 15 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Command/TypeScript/API/Customer.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // CONCRETE CUSTOMER 3 | // ============================== 4 | 5 | export default class Customer { 6 | pay(): string { 7 | return "Payment OK!\n"; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Command/TypeScript/API/Order.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT ORDER 3 | // ============================== 4 | 5 | export default interface Order { 6 | deliver(): string; 7 | } 8 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Interpreter/CoffeeScript/API/Note.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | MusicNotation = require './MusicNotation' 4 | 5 | # ============================== 6 | # CONCRETE (TERMINAL) EXPRESSION 7 | # ============================== 8 | 9 | class Note extends MusicNotation 10 | constructor: (name) -> 11 | super name 12 | 13 | interpret: (sonata) -> 14 | "#{sonata.composer} played #{@_name}\n" 15 | 16 | module.exports = Note 17 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Interpreter/CoffeeScript/API/Sonata.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # CONCRETE CONTEXT 5 | # ============================== 6 | 7 | class Sonata 8 | constructor: (@name, @composer) -> 9 | 10 | getName: -> 11 | @_name 12 | 13 | getComposer: -> 14 | @_composer 15 | 16 | module.exports = Sonata 17 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Interpreter/ECMAScript/ES6/API/Note.js: -------------------------------------------------------------------------------- 1 | import MusicNotation from './MusicNotation'; 2 | 3 | // ============================== 4 | // CONCRETE (TERMINAL) EXPRESSION 5 | // ============================== 6 | 7 | export default class Note extends MusicNotation { 8 | constructor(name) { 9 | super(name); 10 | } 11 | 12 | interpret(sonata) { 13 | return `${sonata.composer} played ${this._name}\n`; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Interpreter/ECMAScript/ES6/API/Sonata.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // CONCRETE CONTEXT 3 | // ============================== 4 | 5 | export default class Sonata { 6 | constructor(name, composer) { 7 | this._name = name; 8 | this._composer = composer; 9 | } 10 | 11 | get name() { 12 | return this._name; 13 | }; 14 | 15 | get composer() { 16 | return this._composer; 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Interpreter/Interpreter.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Behavioral/Interpreter/Interpreter.dia -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Interpreter/Interpreter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Behavioral/Interpreter/Interpreter.png -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Interpreter/TypeScript/API/MusicNotation.ts: -------------------------------------------------------------------------------- 1 | import Sonata from './Sonata'; 2 | 3 | // ============================== 4 | // ABSTRACT EXPRESSION 5 | // ============================== 6 | 7 | abstract class MusicNotation { 8 | protected name: string; 9 | 10 | constructor(name: string) { 11 | this.name = name; 12 | } 13 | 14 | public abstract interpret(sonata: Sonata): string; 15 | } 16 | 17 | export default MusicNotation; 18 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Iterator/CoffeeScript/API/Collection.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # ABSTRACT ITERABLE 5 | # ============================== 6 | 7 | class Collection 8 | constructor: -> 9 | throw new Error "You cannot instantiate an abstract class!" if @constructor is Collection 10 | 11 | list: -> 12 | throw new Error "You cannot call an abstract method!" 13 | 14 | module.exports = Collection 15 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Iterator/CoffeeScript/API/Library.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Collection = require './Collection' 4 | LibraryCatalog = require './LibraryCatalog' 5 | 6 | # ============================== 7 | # CONCRETE ITERABLE 8 | # ============================== 9 | 10 | class Library extends Collection 11 | constructor: (@_books) -> 12 | 13 | list: -> 14 | new LibraryCatalog(@) 15 | 16 | getBooks: -> 17 | @_books 18 | 19 | module.exports = Library 20 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Iterator/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Library = require './API/Library' 4 | 5 | # ============================== 6 | # CLIENT CODE 7 | # ============================== 8 | 9 | # We get the iterator (catalog) from the iterable object (library) 10 | library = new Library ["Foo", "Bar"] 11 | catalog = library.list() 12 | 13 | console.log catalog.next() while catalog.hasNext() 14 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Iterator/ECMAScript/ES5/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var Library = require('./API/Library'); 4 | 5 | // ============================== 6 | // CLIENT CODE 7 | // ============================== 8 | 9 | // We get the iterator (catalog) from the iterable object (library) 10 | var library = new Library(["Foo", "Bar"]), 11 | catalog = library.list(); 12 | 13 | while (catalog.hasNext()) { 14 | console.log(catalog.next()); 15 | } 16 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Iterator/ECMAScript/ES6/API/Collection.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT ITERABLE 3 | // ============================== 4 | 5 | export default class Collection { 6 | constructor() { 7 | if (new.target !== undefined) { 8 | throw new Error("You cannot instantiate an abstract class!"); 9 | } 10 | } 11 | 12 | list() { 13 | throw new Error("You cannot call an abstract method!"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Iterator/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import Library from './API/Library'; 2 | 3 | // ============================== 4 | // CLIENT CODE 5 | // ============================== 6 | 7 | // We get the iterator (catalog) from the iterable object (library) 8 | let library = new Library(["Foo", "Bar"]), 9 | catalog = library.list(); 10 | 11 | while (catalog.hasNext()) { 12 | console.log(catalog.next()); 13 | } 14 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Iterator/Iterator.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Behavioral/Iterator/Iterator.dia -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Iterator/Iterator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Behavioral/Iterator/Iterator.png -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Iterator/TypeScript/API/Catalog.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT ITERATOR 3 | // ============================== 4 | 5 | export default interface Catalog { 6 | hasNext(): boolean; 7 | next(): string; 8 | } 9 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Iterator/TypeScript/API/Collection.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT ITERABLE 3 | // ============================== 4 | 5 | export default interface Collection { 6 | list(): Catalog; 7 | } 8 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Mediator/CoffeeScript/API/Mediator.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # ABSTRACT MEDIATOR 5 | # ============================== 6 | 7 | class Mediator 8 | constructor: -> 9 | throw new Error "You cannot instantiate an abstract class!" if @constructor is Mediator 10 | 11 | send: (message, neighbor) -> 12 | throw new Error "You cannot instantiate an abstract class!" 13 | 14 | module.exports = Mediator 15 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Mediator/Mediator.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Behavioral/Mediator/Mediator.dia -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Mediator/Mediator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Behavioral/Mediator/Mediator.png -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Mediator/TypeScript/API/Mediator.ts: -------------------------------------------------------------------------------- 1 | import Neighbor from './Neighbor'; 2 | 3 | // ============================== 4 | // ABSTRACT MEDIATOR 5 | // ============================== 6 | 7 | export default interface Mediator { 8 | send(message: string, neighbor: Neighbor): string; 9 | } 10 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Memento/CoffeeScript/API/Bookmark.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # MEMENTO 5 | # ============================== 6 | 7 | class Bookmark 8 | constructor: (webpage) -> 9 | @_webpage = webpage 10 | 11 | getPage: -> 12 | @_webpage 13 | 14 | module.exports = Bookmark 15 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Memento/CoffeeScript/API/BookmarksManager.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # CARETAKER 5 | # ============================== 6 | 7 | class BookmarksManager 8 | constructor: -> 9 | @_bookmarks = [] 10 | 11 | addBookmark: (bookmark) -> 12 | @_bookmarks.push(bookmark) 13 | 14 | getBookmark: (index) -> 15 | @_bookmarks[index] 16 | 17 | module.exports = BookmarksManager 18 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Memento/CoffeeScript/API/Browser.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Bookmark = require './Bookmark' 4 | 5 | # ============================== 6 | # ORIGINATOR 7 | # ============================== 8 | 9 | class Browser 10 | constructor: (@_currentPage) -> 11 | 12 | saveCurrentPage: -> 13 | new Bookmark(@_currentPage) 14 | 15 | getCurrentPage: -> 16 | @_currentPage 17 | 18 | setCurrentPage: (@_currentPage) -> 19 | 20 | module.exports = Browser 21 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Memento/ECMAScript/ES5/API/Bookmark.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // ============================== 4 | // MEMENTO 5 | // ============================== 6 | 7 | var Bookmark = function (webpage) { 8 | this._webpage = webpage; 9 | } 10 | 11 | Bookmark.prototype.getPage = function () { 12 | return this._webpage; 13 | }; 14 | 15 | module.exports = Bookmark; 16 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Memento/ECMAScript/ES6/API/Bookmark.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // MEMENTO 3 | // ============================== 4 | 5 | export default class Bookmark { 6 | constructor(webpage) { 7 | this._webpage = webpage; 8 | } 9 | 10 | getPage() { 11 | return this._webpage; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Memento/ECMAScript/ES6/API/BookmarksManager.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // CARETAKER 3 | // ============================== 4 | 5 | export default class BookmarksManager { 6 | constructor() { 7 | this._bookmarks = []; 8 | } 9 | 10 | addBookmark(bookmark) { 11 | this._bookmarks.push(bookmark); 12 | } 13 | 14 | getBookmark(index) { 15 | return this._bookmarks[index]; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Memento/Memento.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Behavioral/Memento/Memento.dia -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Memento/Memento.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Behavioral/Memento/Memento.png -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Memento/TypeScript/API/Bookmark.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // MEMENTO 3 | // ============================== 4 | 5 | export default class Bookmark { 6 | private webpage: string; 7 | 8 | constructor(webpage: string) { 9 | this.webpage = webpage; 10 | } 11 | 12 | public getPage(): string { 13 | return this.webpage; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Observer/CoffeeScript/API/Crocodile.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Predator = require './Predator' 4 | 5 | # ============================== 6 | # CONCRETE OBSERVER 7 | # ============================== 8 | 9 | class Crocodile extends Predator 10 | attack: -> 11 | "Crocodile attack!\n" 12 | 13 | module.exports = Crocodile 14 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Observer/CoffeeScript/API/Gazelle.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Prey = require './Prey' 4 | 5 | # ============================== 6 | # CONCRETE OBSERVABLE 7 | # ============================== 8 | 9 | class Gazelle extends Prey 10 | constructor: -> 11 | super 12 | 13 | module.exports = Gazelle 14 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Observer/CoffeeScript/API/Lion.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Predator = require './Predator' 4 | 5 | # ============================== 6 | # CONCRETE OBSERVER 7 | # ============================== 8 | 9 | class Lion extends Predator 10 | attack: -> 11 | "Lion attack!\n" 12 | 13 | module.exports = Lion 14 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Observer/CoffeeScript/API/Predator.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # ABSTRACT OBSERVER 5 | # ============================== 6 | 7 | class Predator 8 | constructor: -> 9 | throw new Error "You cannot instantiate an abstract class!" if @constructor is Predator 10 | 11 | attack: -> 12 | throw new Error "You cannot call an abstract method!" 13 | 14 | module.exports = Predator 15 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Observer/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Lion = require './API/Lion' 4 | Crocodile = require './API/Crocodile' 5 | Gazelle = require './API/Gazelle' 6 | 7 | # ============================== 8 | # CLIENT CODE 9 | # ============================== 10 | 11 | lion = new Lion 12 | crocodile = new Crocodile 13 | gazelle = new Gazelle 14 | 15 | gazelle.addPredator lion 16 | gazelle.addPredator crocodile 17 | 18 | console.log gazelle.notifyPredators() 19 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Observer/ECMAScript/ES5/API/Gazelle.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var Prey = require('./Prey'); 4 | 5 | // ============================== 6 | // CONCRETE OBSERVABLE 7 | // ============================== 8 | 9 | var Gazelle = function () { 10 | Prey.call(this); 11 | } 12 | Gazelle.prototype = Object.create(Prey.prototype); 13 | Gazelle.prototype.constructor = Gazelle; 14 | 15 | module.exports = Gazelle; 16 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Observer/ECMAScript/ES5/API/Lion.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var Predator = require('./Predator'); 4 | 5 | // ============================== 6 | // CONCRETE OBSERVER 7 | // ============================== 8 | 9 | var Lion = function () {}; 10 | Lion.prototype = Object.create(Predator.prototype); 11 | Lion.prototype.constructor = Lion; 12 | 13 | Lion.prototype.attack = function () { 14 | return "Lion attack!\n"; 15 | }; 16 | 17 | module.exports = Lion; 18 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Observer/ECMAScript/ES6/API/Crocodile.js: -------------------------------------------------------------------------------- 1 | import Predator from './Predator'; 2 | 3 | // ============================== 4 | // CONCRETE OBSERVER 5 | // ============================== 6 | 7 | export default class Crocodile extends Predator { 8 | attack() { 9 | return "Crocodile attack!\n"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Observer/ECMAScript/ES6/API/Gazelle.js: -------------------------------------------------------------------------------- 1 | import Prey from './Prey'; 2 | 3 | // ============================== 4 | // CONCRETE OBSERVABLE 5 | // ============================== 6 | 7 | export default class Gazelle extends Prey { 8 | constructor() { 9 | super(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Observer/ECMAScript/ES6/API/Lion.js: -------------------------------------------------------------------------------- 1 | import Predator from './Predator'; 2 | 3 | // ============================== 4 | // CONCRETE OBSERVER 5 | // ============================== 6 | 7 | export default class Lion extends Predator { 8 | attack() { 9 | return "Lion attack!\n"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Observer/ECMAScript/ES6/API/Predator.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT OBSERVER 3 | // ============================== 4 | 5 | export default class Predator { 6 | constructor() { 7 | if (new.target !== undefined) { 8 | throw new Error("You cannot instantiate an abstract class!"); 9 | } 10 | } 11 | 12 | attack() { 13 | throw new Error("You cannot call an abstract method!"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Observer/Observer.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Behavioral/Observer/Observer.dia -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Observer/Observer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Behavioral/Observer/Observer.png -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Observer/TypeScript/API/Crocodile.ts: -------------------------------------------------------------------------------- 1 | import Predator from './Predator'; 2 | 3 | // ============================== 4 | // CONCRETE OBSERVER 5 | // ============================== 6 | 7 | export default class Crocodile implements Predator { 8 | public attack(): string { 9 | return "Crocodile attack!\n"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Observer/TypeScript/API/Gazelle.ts: -------------------------------------------------------------------------------- 1 | import Prey from './Prey'; 2 | 3 | // ============================== 4 | // CONCRETE OBSERVABLE 5 | // ============================== 6 | 7 | export default class Gazelle extends Prey { 8 | constructor() { 9 | super(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Observer/TypeScript/API/Lion.ts: -------------------------------------------------------------------------------- 1 | import Predator from './Predator'; 2 | 3 | // ============================== 4 | // CONCRETE OBSERVER 5 | // ============================== 6 | 7 | export default class Lion implements Predator { 8 | public attack(): string { 9 | return "Lion attack!\n"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Observer/TypeScript/API/Predator.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT OBSERVER 3 | // ============================== 4 | 5 | export default interface Predator { 6 | attack(): string; 7 | } 8 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/State/CoffeeScript/API/ComputerState.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # ABSTRACT STATE 5 | # ============================== 6 | 7 | class ComputerState 8 | constructor: -> 9 | throw new Error "You cannot instantiate an abstract class!" if @constructor is ComputerState 10 | 11 | power: (pc) -> 12 | throw new Error "You cannot call an abstract method!" 13 | 14 | module.exports = ComputerState 15 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/State/CoffeeScript/API/Off.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | ComputerState = require './ComputerState' 4 | 5 | # ============================== 6 | # CONCRETE STATE 7 | # ============================== 8 | 9 | class Off extends ComputerState 10 | power: (pc) -> 11 | pc.setCurrentState pc.getStates().on 12 | 13 | module.exports = Off 14 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/State/CoffeeScript/API/On.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | ComputerState = require './ComputerState' 4 | 5 | # ============================== 6 | # CONCRETE STATE 7 | # ============================== 8 | 9 | class On extends ComputerState 10 | power: (pc) -> 11 | pc.setCurrentState pc.getStates().off 12 | 13 | module.exports = On 14 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/State/ECMAScript/ES5/API/On.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var ComputerState = require('./ComputerState'); 4 | 5 | // ============================== 6 | // CONCRETE STATE 7 | // ============================== 8 | 9 | var On = function () {}; 10 | On.prototype = Object.create(ComputerState.prototype); 11 | On.prototype.constructor = On; 12 | 13 | On.prototype.power = function (pc) { 14 | pc.setCurrentState(pc.getStates().off); 15 | }; 16 | 17 | module.exports = On; 18 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/State/ECMAScript/ES6/API/ComputerState.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT STATE 3 | // ============================== 4 | 5 | export default class ComputerState { 6 | constructor() { 7 | if (new.target !== undefined) { 8 | throw new Error("You cannot instantiate an abstract class!"); 9 | } 10 | } 11 | 12 | power(pc) { 13 | throw new Error("You cannot call an abstract method!"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/State/ECMAScript/ES6/API/Off.js: -------------------------------------------------------------------------------- 1 | import ComputerState from './ComputerState'; 2 | 3 | // ============================== 4 | // CONCRETE STATE 5 | // ============================== 6 | 7 | export default class Off extends ComputerState { 8 | power(pc) { 9 | pc.setCurrentState(pc.getStates().on); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/State/ECMAScript/ES6/API/On.js: -------------------------------------------------------------------------------- 1 | import ComputerState from './ComputerState'; 2 | 3 | // ============================== 4 | // CONCRETE STATE 5 | // ============================== 6 | 7 | export default class On extends ComputerState { 8 | power(pc) { 9 | pc.setCurrentState(pc.getStates().off); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/State/State.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Behavioral/State/State.dia -------------------------------------------------------------------------------- /GoF/classic/Behavioral/State/State.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Behavioral/State/State.png -------------------------------------------------------------------------------- /GoF/classic/Behavioral/State/TypeScript/API/ComputerState.ts: -------------------------------------------------------------------------------- 1 | import Computer from './Computer'; 2 | 3 | // ============================== 4 | // ABSTRACT STATE 5 | // ============================== 6 | 7 | export default interface ComputerState { 8 | power(pc: Computer): void; 9 | } 10 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/State/TypeScript/API/Off.ts: -------------------------------------------------------------------------------- 1 | import ComputerState from './ComputerState'; 2 | import Computer from './Computer'; 3 | 4 | // ============================== 5 | // CONCRETE STATE 6 | // ============================== 7 | 8 | export default class Off implements ComputerState { 9 | public power(pc: Computer): void { 10 | pc.setCurrentState(pc.getStates().on); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/State/TypeScript/API/On.ts: -------------------------------------------------------------------------------- 1 | import ComputerState from './ComputerState'; 2 | import Computer from './Computer'; 3 | 4 | // ============================== 5 | // CONCRETE STATE 6 | // ============================== 7 | 8 | export default class On implements ComputerState { 9 | public power(pc: Computer): void { 10 | pc.setCurrentState(pc.getStates().off); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Strategy/CoffeeScript/API/Defense.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Strategy = require './Strategy' 4 | 5 | # ============================== 6 | # CONCRETE STRATEGY 7 | # ============================== 8 | 9 | class Defense extends Strategy 10 | fight: -> 11 | "Fight with a defensive style" 12 | 13 | module.exports = Defense 14 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Strategy/CoffeeScript/API/FightingGame.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # CONCRETE CONTEXT 5 | # ============================== 6 | 7 | class FightingGame 8 | constructor: -> 9 | @_strategy = null 10 | 11 | play: -> 12 | @_strategy.fight() 13 | 14 | setStrategy: (fightStyle) -> 15 | @_strategy = fightStyle 16 | 17 | module.exports = FightingGame 18 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Strategy/CoffeeScript/API/Offense.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Strategy = require './Strategy' 4 | 5 | # ============================== 6 | # CONCRETE STRATEGY 7 | # ============================== 8 | 9 | class Offense extends Strategy 10 | fight: -> 11 | "Fight with an offensive style" 12 | 13 | module.exports = Offense 14 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Strategy/CoffeeScript/API/Strategy.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # ABSTRACT STRATEGY 5 | # ============================== 6 | 7 | class Strategy 8 | constructor: -> 9 | throw new Error "You cannot instantiate an abstract class!" if @constructor is Strategy 10 | 11 | fight: -> 12 | throw new Error "You cannot call an abstract method!" 13 | 14 | module.exports = Strategy 15 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Strategy/ECMAScript/ES6/API/Defense.js: -------------------------------------------------------------------------------- 1 | import Strategy from './Strategy'; 2 | 3 | // ============================== 4 | // CONCRETE STRATEGY 5 | // ============================== 6 | 7 | export default class Defense extends Strategy { 8 | fight() { 9 | return "Fight with a defensive style"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Strategy/ECMAScript/ES6/API/FightingGame.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // CONCRETE CONTEXT 3 | // ============================== 4 | 5 | export default class FightingGame { 6 | constructor() { 7 | this._strategy = null; 8 | } 9 | 10 | play() { 11 | return this._strategy.fight(); 12 | } 13 | 14 | setStrategy(fightStyle) { 15 | this._strategy = fightStyle; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Strategy/ECMAScript/ES6/API/Offense.js: -------------------------------------------------------------------------------- 1 | import Strategy from './Strategy'; 2 | 3 | // ============================== 4 | // CONCRETE STRATEGY 5 | // ============================== 6 | 7 | export default class Offense extends Strategy { 8 | fight() { 9 | return "Fight with an offensive style"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Strategy/ECMAScript/ES6/API/Strategy.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT STRATEGY 3 | // ============================== 4 | 5 | export default class Strategy { 6 | constructor() { 7 | if (new.target !== undefined) { 8 | throw new Error("You cannot instantiate an abstract class!"); 9 | } 10 | } 11 | 12 | fight() { 13 | throw new Error("You cannot call an abstract method!"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Strategy/Strategy.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Behavioral/Strategy/Strategy.dia -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Strategy/Strategy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Behavioral/Strategy/Strategy.png -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Strategy/TypeScript/API/Defense.ts: -------------------------------------------------------------------------------- 1 | import Strategy from './Strategy'; 2 | 3 | // ============================== 4 | // CONCRETE STRATEGY 5 | // ============================== 6 | 7 | export default class Defense implements Strategy { 8 | fight(): string { 9 | return "Fight with a defensive style"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Strategy/TypeScript/API/FightingGame.ts: -------------------------------------------------------------------------------- 1 | import Strategy from './Strategy'; 2 | 3 | // ============================== 4 | // CONCRETE CONTEXT 5 | // ============================== 6 | 7 | export default class FightingGame { 8 | private strategy: Strategy; 9 | 10 | play(): string { 11 | return this.strategy.fight(); 12 | } 13 | 14 | setStrategy(fightStyle: Strategy): void { 15 | this.strategy = fightStyle; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Strategy/TypeScript/API/Offense.ts: -------------------------------------------------------------------------------- 1 | import Strategy from './Strategy'; 2 | 3 | // ============================== 4 | // CONCRETE STRATEGY 5 | // ============================== 6 | 7 | export default class Offense implements Strategy { 8 | fight(): string { 9 | return "Fight with an offensive style"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Strategy/TypeScript/API/Strategy.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT STRATEGY 3 | // ============================== 4 | 5 | export default interface Strategy { 6 | fight(): string; 7 | } 8 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Template/CoffeeScript/API/Building.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Home = require './Home' 4 | 5 | # ============================== 6 | # CONCRETE HOME 7 | # ============================== 8 | 9 | class Building extends Home 10 | foundations: -> 11 | "Apartment building foundations" 12 | 13 | walls: -> 14 | "Apartment building walls" 15 | 16 | roof: -> 17 | "Apartment building roof" 18 | 19 | module.exports = Building 20 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Template/CoffeeScript/API/House.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Home = require './Home' 4 | 5 | # ============================== 6 | # CONCRETE HOME 7 | # ============================== 8 | 9 | class House extends Home 10 | foundations: -> 11 | "House foundations" 12 | 13 | walls: -> 14 | "House walls" 15 | 16 | roof: -> 17 | "House roof" 18 | 19 | module.exports = House 20 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Template/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | House = require './API/House' 4 | Building = require './API/Building' 5 | 6 | # ============================== 7 | # CLIENT CODE 8 | # ============================== 9 | 10 | house = new House 11 | building = new Building 12 | 13 | console.log house.build() 14 | console.log building.build() 15 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Template/ECMAScript/ES5/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var House = require('./API/House'), 4 | Building = require('./API/Building'); 5 | 6 | // ============================== 7 | // CLIENT CODE 8 | // ============================== 9 | 10 | var house = new House(), 11 | building = new Building(); 12 | 13 | console.log(house.build()); 14 | console.log(building.build()); 15 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Template/ECMAScript/ES6/API/House.js: -------------------------------------------------------------------------------- 1 | import Home from './Home'; 2 | 3 | // ============================== 4 | // CONCRETE HOME 5 | // ============================== 6 | 7 | export default class House extends Home { 8 | foundations() { 9 | return "House foundations"; 10 | } 11 | 12 | walls() { 13 | return "House walls"; 14 | } 15 | 16 | roof() { 17 | return "House roof"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Template/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import House from './API/House.js'; 2 | import Building from './API/Building'; 3 | 4 | // ============================== 5 | // CLIENT CODE 6 | // ============================== 7 | 8 | let house = new House(), 9 | building = new Building(); 10 | 11 | console.log(house.build()); 12 | console.log(building.build()); 13 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Template/Template.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Behavioral/Template/Template.dia -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Template/Template.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Behavioral/Template/Template.png -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Template/TypeScript/client.ts: -------------------------------------------------------------------------------- 1 | import Home from './API/Home'; 2 | import House from './API/House'; 3 | import Building from './API/Building'; 4 | 5 | // ============================== 6 | // CLIENT CODE 7 | // ============================== 8 | 9 | let house: Home = new House(), 10 | building: Home = new Building(); 11 | 12 | console.log(house.build()); 13 | console.log(building.build()); 14 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Visitor/CoffeeScript/API/Abbey.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | HistoricalMonument = require './HistoricalMonument' 4 | 5 | # ============================== 6 | # CONCRETE MONUMENT 7 | # ============================== 8 | 9 | class Abbey extends HistoricalMonument 10 | accept: (visitor) -> 11 | visitor.visit(@) 12 | 13 | module.exports = Abbey 14 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Visitor/CoffeeScript/API/Castle.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | HistoricalMonument = require './HistoricalMonument' 4 | 5 | # ============================== 6 | # CONCRETE MONUMENT 7 | # ============================== 8 | 9 | class Castle extends HistoricalMonument 10 | accept: (visitor) -> 11 | visitor.visit(@) 12 | 13 | module.exports = Castle 14 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Visitor/CoffeeScript/API/Tourist.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Visitor = require './Visitor' 4 | 5 | # ============================== 6 | # CONCRETE VISITOR 7 | # ============================== 8 | 9 | class Tourist extends Visitor 10 | visit: (monument) -> 11 | "Visiting #{monument.constructor.name}" 12 | 13 | module.exports = Tourist 14 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Visitor/CoffeeScript/API/Visitor.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # ABSTRACT VISITOR 5 | # ============================== 6 | 7 | class Visitor 8 | constructor: -> 9 | throw new Error "You cannot instantiate an abstract class!" if @constructor is Visitor 10 | 11 | visit: (monument) -> 12 | throw new Error "You cannot call an abstract method!" 13 | 14 | module.exports = Visitor 15 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Visitor/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Castle = require './API/Castle' 4 | Abbey = require './API/Abbey' 5 | Tourist = require './API/Tourist' 6 | 7 | # ============================== 8 | # CLIENT CODE 9 | # ============================== 10 | 11 | castle = new Castle 12 | abbey = new Abbey 13 | tourist = new Tourist 14 | 15 | console.log castle.accept tourist 16 | console.log abbey.accept tourist 17 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Visitor/ECMAScript/ES5/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var Castle = require('./API/Castle'), 4 | Abbey = require('./API/Abbey'), 5 | Tourist = require('./API/Tourist'); 6 | 7 | // ============================== 8 | // CLIENT CODE 9 | // ============================== 10 | 11 | var castle = new Castle(), 12 | abbey = new Abbey(), 13 | tourist = new Tourist(); 14 | 15 | console.log(castle.accept(tourist)); 16 | console.log(abbey.accept(tourist)); 17 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Visitor/ECMAScript/ES6/API/Abbey.js: -------------------------------------------------------------------------------- 1 | import HistoricalMonument from './HistoricalMonument'; 2 | 3 | // ============================== 4 | // CONCRETE MONUMENT 5 | // ============================== 6 | 7 | export default class Abbey extends HistoricalMonument { 8 | accept(visitor) { 9 | return visitor.visit(this); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Visitor/ECMAScript/ES6/API/Castle.js: -------------------------------------------------------------------------------- 1 | import HistoricalMonument from './HistoricalMonument'; 2 | 3 | // ============================== 4 | // CONCRETE MONUMENT 5 | // ============================== 6 | 7 | export default class Castle extends HistoricalMonument { 8 | accept(visitor) { 9 | return visitor.visit(this); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Visitor/ECMAScript/ES6/API/Tourist.js: -------------------------------------------------------------------------------- 1 | import Visitor from './Visitor'; 2 | 3 | // ============================== 4 | // CONCRETE VISITOR 5 | // ============================== 6 | 7 | export default class Tourist extends Visitor { 8 | visit(monument) { 9 | return `Visiting ${monument.constructor.name}`; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Visitor/ECMAScript/ES6/API/Visitor.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT VISITOR 3 | // ============================== 4 | 5 | export default class Visitor { 6 | constructor() { 7 | if (new.target !== undefined) { 8 | throw new Error("You cannot instantiate an abstract class!"); 9 | } 10 | } 11 | 12 | visit(monument) { 13 | throw new Error("You cannot call an abstract method!"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Visitor/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import Castle from './API/Castle'; 2 | import Abbey from './API/Abbey'; 3 | import Tourist from './API/Tourist'; 4 | 5 | // ============================== 6 | // CLIENT CODE 7 | // ============================== 8 | 9 | let castle = new Castle(), 10 | abbey = new Abbey(), 11 | tourist = new Tourist(); 12 | 13 | console.log(castle.accept(tourist)); 14 | console.log(abbey.accept(tourist)); 15 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Visitor/TypeScript/API/Abbey.ts: -------------------------------------------------------------------------------- 1 | import HistoricalMonument from './HistoricalMonument'; 2 | import Visitor from './Visitor'; 3 | 4 | // ============================== 5 | // CONCRETE MONUMENT 6 | // ============================== 7 | 8 | export default class Abbey implements HistoricalMonument { 9 | public accept(visitor: Visitor): string { 10 | return visitor.visit(this); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Visitor/TypeScript/API/Castle.ts: -------------------------------------------------------------------------------- 1 | import HistoricalMonument from './HistoricalMonument'; 2 | import Visitor from './Visitor'; 3 | 4 | // ============================== 5 | // CONCRETE MONUMENT 6 | // ============================== 7 | 8 | export default class Castle implements HistoricalMonument { 9 | public accept(visitor: Visitor): string { 10 | return visitor.visit(this); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Visitor/TypeScript/API/HistoricalMonument.ts: -------------------------------------------------------------------------------- 1 | import Visitor from './Visitor'; 2 | 3 | // ============================== 4 | // ABSTRACT MONUMENT 5 | // ============================== 6 | 7 | export default interface HistoricalMonument { 8 | accept(visitor: Visitor): string; 9 | } 10 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Visitor/TypeScript/API/Visitor.ts: -------------------------------------------------------------------------------- 1 | import HistoricalMonument from './HistoricalMonument'; 2 | 3 | // ============================== 4 | // ABSTRACT VISITOR 5 | // ============================== 6 | 7 | export default interface Visitor { 8 | visit(monument: HistoricalMonument): string; 9 | } 10 | -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Visitor/Visitor.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Behavioral/Visitor/Visitor.dia -------------------------------------------------------------------------------- /GoF/classic/Behavioral/Visitor/Visitor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Behavioral/Visitor/Visitor.png -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/AbstractFactory.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Creational/AbstractFactory/AbstractFactory.dia -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/AbstractFactory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Creational/AbstractFactory/AbstractFactory.png -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/CoffeeScript/API/Debian.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | LinuxDistro = require './LinuxDistro' 4 | 5 | # ============================== 6 | # CONCRETE GNU/LINUX DISTRO 7 | # ============================== 8 | 9 | class Debian extends LinuxDistro 10 | constructor: -> 11 | super "Debian" 12 | 13 | module.exports = Debian 14 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/CoffeeScript/API/LinuxDistro.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # ABSTRACT GNU/LINUX DISTRO 5 | # ============================== 6 | 7 | class LinuxDistro 8 | constructor: (name) -> 9 | throw new Error "You cannot instantiate an abstract class!" if @constructor is LinuxDistro 10 | @name = name 11 | 12 | bootLinux: -> 13 | "#{@name} is booting..." 14 | 15 | module.exports = LinuxDistro 16 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/CoffeeScript/API/MacRelease.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # ABSTRACT MAC OS RELEASE 5 | # ============================== 6 | 7 | class MacRelease 8 | constructor: (name) -> 9 | throw new Error "You cannot instantiate an abstract class!" if @constructor is MacRelease 10 | @name = name 11 | 12 | bootMac: -> 13 | "#{@name} is booting..." 14 | 15 | module.exports = MacRelease 16 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/CoffeeScript/API/OS9.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | MacRelease = require './MacRelease' 4 | 5 | # ============================== 6 | # CONCRETE MAC OS RELEASE 7 | # ============================== 8 | 9 | class OS9 extends MacRelease 10 | constructor: -> 11 | super "Mac OS 9" 12 | 13 | module.exports = OS9 14 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/CoffeeScript/API/OSX.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | MacRelease = require './MacRelease' 4 | 5 | # ============================== 6 | # CONCRETE MAC OS RELEASE 7 | # ============================== 8 | 9 | class OSX extends MacRelease 10 | constructor: -> 11 | super "Mac OS X" 12 | 13 | module.exports = OSX 14 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/CoffeeScript/API/RedHat.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | LinuxDistro = require './LinuxDistro' 4 | 5 | # ============================== 6 | # CONCRETE GNU/LINUX DISTRO 7 | # ============================== 8 | 9 | class RedHat extends LinuxDistro 10 | constructor: -> 11 | super "RedHat" 12 | 13 | module.exports = RedHat 14 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/CoffeeScript/API/Vista.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | WindowsVersion = require './WindowsVersion' 4 | 5 | # ============================== 6 | # CONCRETE WINDOWS VERSION 7 | # ============================== 8 | 9 | class Vista extends WindowsVersion 10 | constructor: -> 11 | super "Windows Vista" 12 | 13 | module.exports = Vista 14 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/CoffeeScript/API/XP.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | WindowsVersion = require './WindowsVersion' 4 | 5 | # ============================== 6 | # CONCRETE WINDOWS VERSION 7 | # ============================== 8 | 9 | class XP extends WindowsVersion 10 | constructor: -> 11 | super "Windows XP" 12 | 13 | module.exports = XP 14 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/ECMAScript/ES5/API/Debian.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var LinuxDistro = require('./LinuxDistro'); 4 | 5 | // ============================== 6 | // CONCRETE GNU/LINUX DISTRO 7 | // ============================== 8 | 9 | var Debian = function () { 10 | LinuxDistro.call(this, "Debian"); 11 | }; 12 | Debian.prototype = Object.create(LinuxDistro.prototype); 13 | Debian.prototype.constructor = Debian; 14 | 15 | module.exports = Debian; 16 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/ECMAScript/ES5/API/OS9.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var MacRelease = require('./MacRelease'); 4 | 5 | // ============================== 6 | // CONCRETE MAC OS RELEASE 7 | // ============================== 8 | 9 | var OS9 = function () { 10 | MacRelease.call(this, "Mac OS 9"); 11 | }; 12 | OS9.prototype = Object.create(MacRelease.prototype); 13 | OS9.prototype.constructor = OS9; 14 | 15 | module.export = OS9; 16 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/ECMAScript/ES5/API/OSX.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var MacRelease = require('./MacRelease'); 4 | 5 | // ============================== 6 | // CONCRETE MAC OS RELEASE 7 | // ============================== 8 | 9 | var OSX = function () { 10 | MacRelease.call(this, "Mac OS X"); 11 | }; 12 | OSX.prototype = Object.create(MacRelease.prototype); 13 | OSX.prototype.constructor = OSX; 14 | 15 | module.exports = OSX; 16 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/ECMAScript/ES5/API/RedHat.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var LinuxDistro = require('./LinuxDistro'); 4 | 5 | // ============================== 6 | // CONCRETE GNU/LINUX DISTRO 7 | // ============================== 8 | 9 | var RedHat = function () { 10 | LinuxDistro.call(this, "RedHat"); 11 | }; 12 | RedHat.prototype = Object.create(LinuxDistro.prototype); 13 | RedHat.prototype.constructor = RedHat; 14 | 15 | module.exports = RedHat; 16 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/ECMAScript/ES5/API/Vista.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var WindowsVersion = require('./WindowsVersion'); 4 | 5 | // ============================== 6 | // CONCRETE WINDOWS VERSION 7 | // ============================== 8 | 9 | var Vista = function () { 10 | WindowsVersion.call(this, "Windows Vista"); 11 | }; 12 | Vista.prototype = Object.create(WindowsVersion.prototype); 13 | Vista.prototype.constructor = Vista; 14 | 15 | module.exports = Vista; 16 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/ECMAScript/ES5/API/XP.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var WindowsVersion = require('./WindowsVersion'); 4 | 5 | // ============================== 6 | // CONCRETE WINDOWS VERSION 7 | // ============================== 8 | 9 | var XP = function () { 10 | WindowsVersion.call(this, "Windows XP"); 11 | }; 12 | XP.prototype = Object.create(WindowsVersion.prototype); 13 | XP.prototype.constructor = XP; 14 | 15 | module.exports = XP; 16 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/ECMAScript/ES6/API/Debian.js: -------------------------------------------------------------------------------- 1 | import LinuxDistro from './LinuxDistro'; 2 | 3 | // ============================== 4 | // CONCRETE GNU/LINUX DISTRO 5 | // ============================== 6 | 7 | export default class Debian extends LinuxDistro { 8 | constructor() { 9 | super("Debian"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/ECMAScript/ES6/API/OS9.js: -------------------------------------------------------------------------------- 1 | import MacRelease from './MacRelease'; 2 | 3 | // ============================== 4 | // CONCRETE MAC OS RELEASE 5 | // ============================== 6 | 7 | export default class OS9 extends MacRelease { 8 | constructor() { 9 | super("Mac OS 9"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/ECMAScript/ES6/API/OSX.js: -------------------------------------------------------------------------------- 1 | import MacRelease from './MacRelease'; 2 | 3 | // ============================== 4 | // CONCRETE MAC OS RELEASE 5 | // ============================== 6 | 7 | export default class OSX extends MacRelease { 8 | constructor() { 9 | super("Mac OS X"); 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/ECMAScript/ES6/API/RedHat.js: -------------------------------------------------------------------------------- 1 | import LinuxDistro from './LinuxDistro'; 2 | 3 | // ============================== 4 | // CONCRETE GNU/LINUX DISTRO 5 | // ============================== 6 | 7 | export default class RedHat extends LinuxDistro { 8 | constructor() { 9 | super("RedHat"); 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/ECMAScript/ES6/API/Vista.js: -------------------------------------------------------------------------------- 1 | import WindowsVersion from './WindowsVersion'; 2 | 3 | // ============================== 4 | // CONCRETE WINDOWS VERSION 5 | // ============================== 6 | 7 | export default class Vista extends WindowsVersion { 8 | constructor() { 9 | super("Windows Vista"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/ECMAScript/ES6/API/XP.js: -------------------------------------------------------------------------------- 1 | import WindowsVersion from './WindowsVersion'; 2 | 3 | // ============================== 4 | // CONCRETE WINDOWS VERSION 5 | // ============================== 6 | 7 | export default class XP extends WindowsVersion { 8 | constructor() { 9 | super("Windows XP"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/TypeScript/API/Debian.ts: -------------------------------------------------------------------------------- 1 | import LinuxDistro from './LinuxDistro'; 2 | 3 | // ============================== 4 | // CONCRETE GNU/LINUX DISTRO 5 | // ============================== 6 | 7 | export default class Debian extends LinuxDistro { 8 | constructor() { 9 | super("Debian"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/TypeScript/API/LinuxDistro.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT GNU/LINUX DISTRO 3 | // ============================== 4 | 5 | abstract class LinuxDistro { 6 | protected name: string; 7 | 8 | constructor(name: string) { 9 | this.name = name; 10 | } 11 | 12 | public bootLinux(): string { 13 | return `${this.name} is booting...`; 14 | } 15 | } 16 | 17 | export default LinuxDistro; 18 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/TypeScript/API/MacRelease.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT MAC OS RELEASE 3 | // ============================== 4 | 5 | abstract class MacRelease { 6 | protected name: string; 7 | 8 | constructor(name: string) { 9 | this.name = name; 10 | } 11 | 12 | public bootMac(): string { 13 | return `${this.name} is booting...`; 14 | } 15 | } 16 | 17 | export default MacRelease; 18 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/TypeScript/API/OS9.ts: -------------------------------------------------------------------------------- 1 | import MacRelease from './MacRelease'; 2 | 3 | // ============================== 4 | // CONCRETE MAC OS RELEASE 5 | // ============================== 6 | 7 | export default class OS9 extends MacRelease { 8 | constructor() { 9 | super("Mac OS 9"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/TypeScript/API/OSX.ts: -------------------------------------------------------------------------------- 1 | import MacRelease from './MacRelease'; 2 | 3 | // ============================== 4 | // CONCRETE MAC OS RELEASE 5 | // ============================== 6 | 7 | export default class OSX extends MacRelease { 8 | constructor() { 9 | super("Mac OS X"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/TypeScript/API/RedHat.ts: -------------------------------------------------------------------------------- 1 | import LinuxDistro from './LinuxDistro'; 2 | 3 | // ============================== 4 | // CONCRETE GNU/LINUX DISTRO 5 | // ============================== 6 | 7 | export default class RedHat extends LinuxDistro { 8 | constructor() { 9 | super("RedHat"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/TypeScript/API/Vista.ts: -------------------------------------------------------------------------------- 1 | import WindowsVersion from './WindowsVersion'; 2 | 3 | // ============================== 4 | // CONCRETE WINDOWS VERSION 5 | // ============================== 6 | 7 | export default class Vista extends WindowsVersion { 8 | constructor() { 9 | super("Windows Vista"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/TypeScript/API/WindowsVersion.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT WINDOWS VERSION 3 | // ============================== 4 | 5 | abstract class WindowsVersion { 6 | protected name: string; 7 | 8 | constructor(name: string) { 9 | this.name = name; 10 | } 11 | 12 | public bootWindows(): string { 13 | return `${this.name} is booting...`; 14 | } 15 | } 16 | 17 | export default WindowsVersion; 18 | -------------------------------------------------------------------------------- /GoF/classic/Creational/AbstractFactory/TypeScript/API/XP.ts: -------------------------------------------------------------------------------- 1 | import WindowsVersion from './WindowsVersion'; 2 | 3 | // ============================== 4 | // CONCRETE WINDOWS VERSION 5 | // ============================== 6 | 7 | export default class XP extends WindowsVersion { 8 | constructor() { 9 | super("Windows XP"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Builder/Builder.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Creational/Builder/Builder.dia -------------------------------------------------------------------------------- /GoF/classic/Creational/Builder/Builder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Creational/Builder/Builder.png -------------------------------------------------------------------------------- /GoF/classic/Creational/Builder/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Geek = require './API/Geek' 4 | Manufacturer = require './API/Manufacturer' 5 | 6 | # ============================== 7 | # CLIENT CODE 8 | # ============================== 9 | 10 | geek = new Geek 11 | pc = Manufacturer.manufacture geek 12 | 13 | console.log pc 14 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Builder/ECMAScript/ES5/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var Geek = require('./API/Geek'), 4 | Manufacturer = require('./API/Manufacturer'); 5 | 6 | // ============================== 7 | // CLIENT CODE 8 | // ============================== 9 | 10 | var geek = new Geek(), 11 | pc = Manufacturer.manufacture(geek); 12 | 13 | console.log(pc); 14 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Builder/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import Geek from './API/Geek'; 2 | import Manufacturer from './API/Manufacturer'; 3 | 4 | // ============================== 5 | // CLIENT CODE 6 | // ============================== 7 | 8 | let geek = new Geek(), 9 | pc = Manufacturer.manufacture(geek); 10 | 11 | console.log(pc); 12 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Builder/TypeScript/client.ts: -------------------------------------------------------------------------------- 1 | import Geek from './API/Geek'; 2 | import Manufacturer from './API/Manufacturer'; 3 | 4 | // ============================== 5 | // CLIENT CODE 6 | // ============================== 7 | 8 | let geek: Geek = new Geek(), 9 | pc: string = Manufacturer.manufacture(geek); 10 | 11 | console.log(pc); 12 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Factory/CoffeeScript/API/Debian.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | LinuxDistro = require './LinuxDistro' 4 | 5 | # ============================== 6 | # CONCRETE GNU/LINUX DISTRO 7 | # ============================== 8 | 9 | class Debian extends LinuxDistro 10 | constructor: -> 11 | super "Debian" 12 | 13 | module.exports = Debian 14 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Factory/CoffeeScript/API/LinuxDistro.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # ABSTRACT GNU/LINUX DISTRO 5 | # ============================== 6 | 7 | class LinuxDistro 8 | constructor: (name) -> 9 | throw new Error "You cannot instantiate an abstract class!" if @constructor is LinuxDistro 10 | @name = name 11 | 12 | boot: -> 13 | "#{@name} is booting..." 14 | 15 | module.exports = LinuxDistro 16 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Factory/CoffeeScript/API/RedHat.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | LinuxDistro = require './LinuxDistro' 4 | 5 | # ============================== 6 | # CONCRETE GNU/LINUX DISTRO 7 | # ============================== 8 | 9 | class RedHat extends LinuxDistro 10 | constructor: -> 11 | super "RedHat" 12 | 13 | module.exports = RedHat 14 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Factory/CoffeeScript/API/Slackware.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | LinuxDistro = require './LinuxDistro' 4 | 5 | # ============================== 6 | # CONCRETE GNU/LINUX DISTRO 7 | # ============================== 8 | 9 | class Slackware extends LinuxDistro 10 | constructor: -> 11 | super "Slackware" 12 | 13 | module.exports = Slackware 14 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Factory/ECMAScript/ES5/API/Debian.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var LinuxDistro = require('./LinuxDistro'); 4 | 5 | // ============================== 6 | // CONCRETE GNU/LINUX DISTRO 7 | // ============================== 8 | 9 | var Debian = function () { 10 | LinuxDistro.call(this, "Debian"); 11 | }; 12 | Debian.prototype = Object.create(LinuxDistro.prototype); 13 | Debian.prototype.constructor = Debian; 14 | 15 | module.exports = Debian; 16 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Factory/ECMAScript/ES5/API/RedHat.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var LinuxDistro = require('./LinuxDistro'); 4 | 5 | // ============================== 6 | // CONCRETE GNU/LINUX DISTRO 7 | // ============================== 8 | 9 | var RedHat = function () { 10 | LinuxDistro.call(this, "RedHat"); 11 | }; 12 | RedHat.prototype = Object.create(LinuxDistro.prototype); 13 | RedHat.prototype.constructor = RedHat; 14 | 15 | module.exports = RedHat; 16 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Factory/ECMAScript/ES5/API/Slackware.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var LinuxDistro = require('./LinuxDistro'); 4 | 5 | // ============================== 6 | // CONCRETE GNU/LINUX DISTRO 7 | // ============================== 8 | 9 | var Slackware = function () { 10 | LinuxDistro.call(this, "Slackware"); 11 | }; 12 | Slackware.prototype = Object.create(LinuxDistro.prototype); 13 | Slackware.prototype.constructor = Slackware; 14 | 15 | module.exports = Slackware; 16 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Factory/ECMAScript/ES6/API/Debian.js: -------------------------------------------------------------------------------- 1 | import LinuxDistro from './LinuxDistro'; 2 | 3 | // ============================== 4 | // CONCRETE GNU/LINUX DISTRO 5 | // ============================== 6 | 7 | export default class Debian extends LinuxDistro { 8 | constructor() { 9 | super(Debian.name); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Factory/ECMAScript/ES6/API/RedHat.js: -------------------------------------------------------------------------------- 1 | import LinuxDistro from './LinuxDistro'; 2 | 3 | // ============================== 4 | // CONCRETE GNU/LINUX DISTRO 5 | // ============================== 6 | 7 | export default class RedHat extends LinuxDistro { 8 | constructor() { 9 | super(RedHat.name); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Factory/ECMAScript/ES6/API/Slackware.js: -------------------------------------------------------------------------------- 1 | import LinuxDistro from './LinuxDistro'; 2 | 3 | // ============================== 4 | // CONCRETE GNU/LINUX DISTRO 5 | // ============================== 6 | 7 | export default class Slackware extends LinuxDistro { 8 | constructor() { 9 | super(Slackware.name); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Factory/Factory.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Creational/Factory/Factory.dia -------------------------------------------------------------------------------- /GoF/classic/Creational/Factory/Factory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Creational/Factory/Factory.png -------------------------------------------------------------------------------- /GoF/classic/Creational/Factory/TypeScript/API/Debian.ts: -------------------------------------------------------------------------------- 1 | import LinuxDistro from './LinuxDistro'; 2 | 3 | // ============================== 4 | // CONCRETE GNU/LINUX DISTRO 5 | // ============================== 6 | 7 | export default class Debian extends LinuxDistro { 8 | constructor() { 9 | super("Debian"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Factory/TypeScript/API/LinuxDistro.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT GNU/LINUX DISTRO 3 | // ============================== 4 | 5 | abstract class LinuxDistro { 6 | private name: string; 7 | 8 | constructor(name: string) { 9 | this.name = name; 10 | } 11 | 12 | public boot(): string { 13 | return `${this.name} is booting...`; 14 | } 15 | } 16 | 17 | export default LinuxDistro; 18 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Factory/TypeScript/API/RedHat.ts: -------------------------------------------------------------------------------- 1 | import LinuxDistro from './LinuxDistro'; 2 | 3 | // ============================== 4 | // CONCRETE GNU/LINUX DISTRO 5 | // ============================== 6 | 7 | export default class RedHat extends LinuxDistro { 8 | constructor() { 9 | super("RedHat"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Factory/TypeScript/API/Slackware.ts: -------------------------------------------------------------------------------- 1 | import LinuxDistro from './LinuxDistro'; 2 | 3 | // ============================== 4 | // CONCRETE GNU/LINUX DISTRO 5 | // ============================== 6 | 7 | export default class Slackware extends LinuxDistro { 8 | constructor() { 9 | super("Slackware"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Prototype/CoffeeScript/API/PaperSheet.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # ABSTRACT PROTOTYPE 5 | # ============================== 6 | 7 | class PaperSheet 8 | constructor: -> 9 | throw new Error "You cannot instantiate an abstract class!" if @constructor is PaperSheet 10 | 11 | photocopy: -> 12 | throw new Error "You cannot call an abstract method!" 13 | 14 | module.exports = PaperSheet 15 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Prototype/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Invoice = require './API/Invoice' 4 | 5 | # ============================== 6 | # CLIENT CODE 7 | # ============================== 8 | 9 | invoice = new Invoice 42, "€" 10 | copy = invoice.photocopy() 11 | 12 | console.log copy.price # 42 13 | console.log copy.currency # € 14 | console.log copy is invoice # false (the copy is not the original invoice: it is a new object!) 15 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Prototype/ECMAScript/ES5/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var Invoice = require('./API/Invoice'); 4 | 5 | // ============================== 6 | // CLIENT CODE 7 | // ============================== 8 | 9 | var invoice = new Invoice(42, "€"), 10 | copy = invoice.photocopy(); 11 | 12 | console.log(copy.price); // 42 13 | console.log(copy.currency); // € 14 | console.log(copy === invoice); // false (the copy is not the original invoice: it is a new object!) 15 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Prototype/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import Invoice from './API/Invoice'; 2 | 3 | // ============================== 4 | // CLIENT CODE 5 | // ============================== 6 | 7 | let invoice = new Invoice(42, "€"), 8 | copy = invoice.photocopy(); 9 | 10 | console.log(copy.price); // 42 11 | console.log(copy.currency); // € 12 | console.log(copy === invoice); // false (the copy is not the original invoice: it is a new object!) 13 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Prototype/Prototype.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Creational/Prototype/Prototype.dia -------------------------------------------------------------------------------- /GoF/classic/Creational/Prototype/Prototype.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Creational/Prototype/Prototype.png -------------------------------------------------------------------------------- /GoF/classic/Creational/Prototype/TypeScript/API/PaperSheet.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT PROTOTYPE 3 | // ============================== 4 | 5 | export default interface PaperSheet { 6 | photocopy(): PaperSheet; // clone method 7 | } 8 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Prototype/TypeScript/client.ts: -------------------------------------------------------------------------------- 1 | import Invoice from './API/Invoice'; 2 | 3 | // ============================== 4 | // CLIENT CODE 5 | // ============================== 6 | 7 | let invoice: Invoice = new Invoice(42, "€"), 8 | copy: Invoice = invoice.photocopy(); 9 | 10 | console.log(copy.getPrice()); // 42 11 | console.log(copy.getCurrency()); // € 12 | console.log(copy === invoice); // false (the copy is not the original invoice: it is a new object!) 13 | -------------------------------------------------------------------------------- /GoF/classic/Creational/Singleton/Singleton.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Creational/Singleton/Singleton.dia -------------------------------------------------------------------------------- /GoF/classic/Creational/Singleton/Singleton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Creational/Singleton/Singleton.png -------------------------------------------------------------------------------- /GoF/classic/Structural/Adapter/Adapter.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Structural/Adapter/Adapter.dia -------------------------------------------------------------------------------- /GoF/classic/Structural/Adapter/Adapter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Structural/Adapter/Adapter.png -------------------------------------------------------------------------------- /GoF/classic/Structural/Adapter/CoffeeScript/API/AnalogInterface.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # ABSTRACT CONNECTION 5 | # ============================== 6 | 7 | class AnalogInterface 8 | constructor: -> 9 | throw new Error "You cannot instantiate an abstract class!" if @constructor is AnalogInterface 10 | 11 | handleAnalogSignal: -> 12 | throw new Error "You cannot call an abstract method!" 13 | 14 | module.exports = AnalogInterface 15 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Adapter/CoffeeScript/API/VGA.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | AnalogInterface = require './AnalogInterface' 4 | 5 | # ============================== 6 | # CONCRETE CONNECTION 7 | # ============================== 8 | 9 | # VGA has its own interface which handles images only through an analog signal 10 | class VGA extends AnalogInterface 11 | handleAnalogSignal: -> 12 | "Interface: VGA\nData: images\nSignal: analog\n" 13 | 14 | module.exports = VGA 15 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Adapter/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | HDMIToVGAAdapter = require './API/HDMIToVGAAdapter' 4 | 5 | # ============================== 6 | # CLIENT CODE 7 | # ============================== 8 | 9 | adapter = new HDMIToVGAAdapter 10 | 11 | console.log adapter.handleDigitalSignal() # Your computer uses HDMI and your projetor uses VGA 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Adapter/ECMAScript/ES5/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var HDMIToVGAAdapter = require('./API/HDMIToVGAAdapter'); 4 | 5 | // ============================== 6 | // CLIENT CODE 7 | // ============================== 8 | 9 | var adapter = new HDMIToVGAAdapter(); 10 | 11 | console.log(adapter.handleDigitalSignal()); // Your computer uses HDMI and your projector uses VGA 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Adapter/ECMAScript/ES6/API/VGA.js: -------------------------------------------------------------------------------- 1 | import AnalogInterface from './AnalogInterface'; 2 | 3 | // ============================== 4 | // CONCRETE CONNECTION 5 | // ============================== 6 | 7 | // VGA has its own interface which handles images only through an analog signal 8 | export default class VGA extends AnalogInterface { 9 | handleAnalogSignal() { 10 | return "Interface: VGA\nData: images\nSignal: analog\n"; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Adapter/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import HDMIToVGAAdapter from './API/HDMIToVGAAdapter'; 2 | 3 | // ============================== 4 | // CLIENT CODE 5 | // ============================== 6 | 7 | let adapter = new HDMIToVGAAdapter(); 8 | 9 | console.log(adapter.handleDigitalSignal()); 10 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Adapter/TypeScript/API/AnalogInterface.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT CONNECTION 3 | // ============================== 4 | 5 | export default interface AnalogInterface { 6 | handleAnalogSignal(): string; 7 | } 8 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Adapter/TypeScript/API/DigitalInterface.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT CONNECTION 3 | // ============================== 4 | 5 | export default interface DigitalInterface { 6 | handleDigitalSignal(): string; 7 | } 8 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Adapter/TypeScript/API/HDMIToVGAAdapter.ts: -------------------------------------------------------------------------------- 1 | import DigitalInterface from './DigitalInterface'; 2 | import VGA from './VGA'; 3 | 4 | // ============================== 5 | // CONCRETE CONNECTION 6 | // ============================== 7 | 8 | export default class HDMIToVGAAdapter implements DigitalInterface { 9 | private vga: VGA = new VGA(); 10 | 11 | public handleDigitalSignal(): string { 12 | return this.vga.handleAnalogSignal(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Adapter/TypeScript/API/VGA.ts: -------------------------------------------------------------------------------- 1 | import AnalogInterface from './AnalogInterface'; 2 | 3 | // ============================== 4 | // CONCRETE CONNECTION 5 | // ============================== 6 | 7 | // VGA has its own interface which handles images only through an analog signal 8 | export default class VGA implements AnalogInterface { 9 | public handleAnalogSignal(): string { 10 | return "Interface: VGA\nData: images\nSignal: analog\n"; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Adapter/TypeScript/client.ts: -------------------------------------------------------------------------------- 1 | import HDMIToVGAAdapter from './API/HDMIToVGAAdapter'; 2 | 3 | // ============================== 4 | // CLIENT CODE 5 | // ============================== 6 | 7 | let adapter: HDMIToVGAAdapter = new HDMIToVGAAdapter(); 8 | 9 | console.log(adapter.handleDigitalSignal()); // Your computer uses HDMI and your projector uses VGA 10 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Bridge/Bridge.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Structural/Bridge/Bridge.dia -------------------------------------------------------------------------------- /GoF/classic/Structural/Bridge/Bridge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Structural/Bridge/Bridge.png -------------------------------------------------------------------------------- /GoF/classic/Structural/Bridge/CoffeeScript/API/Carbonara.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Sauce = require './Sauce' 4 | 5 | # ============================== 6 | # CONCRETE SAUCES 7 | # ============================== 8 | 9 | class Carbonara extends Sauce 10 | ingredients: -> 11 | "Carbonara (eggs, bacon, black pepper, grated cheese)" 12 | 13 | module.exports = Carbonara 14 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Bridge/CoffeeScript/API/Pasta.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Recipe = require './Recipe' 4 | 5 | # ============================== 6 | # CONCRETE RECIPE 7 | # ============================== 8 | 9 | class Pasta extends Recipe 10 | cook: -> 11 | "Pasta with #{@_sauce.ingredients()}" 12 | 13 | module.exports = Pasta 14 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Bridge/CoffeeScript/API/Pesto.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Sauce = require './Sauce' 4 | 5 | # ============================== 6 | # CONCRETE SAUCES 7 | # ============================== 8 | 9 | class Pesto extends Sauce 10 | ingredients: -> 11 | "Pesto (basil, garlic, oil, grated cheese, pine nuts)" 12 | 13 | module.exports = Pesto 14 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Bridge/CoffeeScript/API/Recipe.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # ABSTRACTIONS 5 | # ============================== 6 | 7 | class Recipe 8 | constructor: (sauce) -> 9 | throw new Error "You cannot instantiate an abstract class!" if @constructor is Recipe 10 | @_sauce = sauce 11 | 12 | cook: -> 13 | throw new Error "You cannot call an abstract class!" 14 | 15 | module.exports = Recipe 16 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Bridge/CoffeeScript/API/Risotto.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Recipe = require './Recipe' 4 | 5 | # ============================== 6 | # CONCRETE RECIPE 7 | # ============================== 8 | 9 | class Risotto extends Recipe 10 | cook: -> 11 | "Risotto with #{@_sauce.ingredients()}" 12 | 13 | module.exports = Risotto 14 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Bridge/CoffeeScript/API/Sauce.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # ABSTRACTION 5 | # ============================== 6 | 7 | class Sauce 8 | constructor: -> 9 | throw new Error "You cannot call an abstract method!" if @constructor is Sauce 10 | 11 | ingredients: -> 12 | throw new Error "You cannot call an abstract method!" 13 | 14 | module.exports = Sauce 15 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Bridge/ECMAScript/ES6/API/Carbonara.js: -------------------------------------------------------------------------------- 1 | import Sauce from './Sauce'; 2 | 3 | // ============================== 4 | // CONCRETE SAUCE 5 | // ============================== 6 | 7 | export default class Carbonara extends Sauce { 8 | ingredients() { 9 | return "Carbonara (eggs, bacon, black pepper, grated cheese)"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Bridge/ECMAScript/ES6/API/Pasta.js: -------------------------------------------------------------------------------- 1 | import Recipe from './Recipe'; 2 | 3 | // ============================== 4 | // CONCRETE RECIPE 5 | // ============================== 6 | 7 | export default class Pasta extends Recipe { 8 | cook() { 9 | return `Pasta with ${this._sauce.ingredients()}`; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Bridge/ECMAScript/ES6/API/Pesto.js: -------------------------------------------------------------------------------- 1 | import Sauce from './Sauce'; 2 | 3 | // ============================== 4 | // CONCRETE SAUCE 5 | // ============================== 6 | 7 | export default class Pesto extends Sauce { 8 | ingredients() { 9 | return "Pesto (basil, garlic, oil, grated cheese, pine nuts)"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Bridge/ECMAScript/ES6/API/Risotto.js: -------------------------------------------------------------------------------- 1 | import Recipe from './Recipe'; 2 | 3 | // ============================== 4 | // CONCRETE RECIPE 5 | // ============================== 6 | 7 | export default class Risotto extends Recipe { 8 | cook() { 9 | return `Risotto with ${this._sauce.ingredients()}`; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Bridge/ECMAScript/ES6/API/Sauce.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACTION 3 | // ============================== 4 | 5 | export default class Sauce { 6 | constructor() { 7 | if (new.target !== undefined) { 8 | throw new Error("You cannot call an abstract method!"); 9 | } 10 | } 11 | 12 | ingredients() { 13 | throw new Error("You cannot call an abstract method!"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Bridge/TypeScript/API/Carbonara.ts: -------------------------------------------------------------------------------- 1 | import Sauce from './Sauce'; 2 | 3 | // ============================== 4 | // CONCRETE SAUCE 5 | // ============================== 6 | 7 | export default class Carbonara implements Sauce { 8 | public ingredients(): string { 9 | return "Carbonara (eggs, bacon, black pepper, grated cheese)"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Bridge/TypeScript/API/Pasta.ts: -------------------------------------------------------------------------------- 1 | import Recipe from './Recipe'; 2 | 3 | // ============================== 4 | // CONCRETE RECIPE 5 | // ============================== 6 | 7 | export default class Pasta extends Recipe { 8 | public cook(): string { 9 | return `Pasta with ${this.sauce.ingredients()}`; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Bridge/TypeScript/API/Pesto.ts: -------------------------------------------------------------------------------- 1 | import Sauce from './Sauce'; 2 | 3 | // ============================== 4 | // CONCRETE SAUCE 5 | // ============================== 6 | 7 | export default class Pesto implements Sauce { 8 | public ingredients(): string { 9 | return "Pesto (basil, garlic, oil, grated cheese, pine nuts)"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Bridge/TypeScript/API/Recipe.ts: -------------------------------------------------------------------------------- 1 | import Sauce from './Sauce'; 2 | 3 | // ============================== 4 | // ABSTRACTIONS 5 | // ============================== 6 | 7 | abstract class Recipe { 8 | protected sauce: Sauce; 9 | 10 | constructor(sauce: Sauce) { 11 | this.sauce = sauce; 12 | } 13 | 14 | public abstract cook(): string; 15 | } 16 | 17 | export default Recipe; 18 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Bridge/TypeScript/API/Risotto.ts: -------------------------------------------------------------------------------- 1 | import Recipe from './Recipe'; 2 | 3 | // ============================== 4 | // CONCRETE RECIPE 5 | // ============================== 6 | 7 | export default class Risotto extends Recipe { 8 | public cook(): string { 9 | return `Risotto with ${this.sauce.ingredients()}`; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Bridge/TypeScript/API/Sauce.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACTION 3 | // ============================== 4 | 5 | export default interface Sauce { 6 | ingredients(): string; 7 | } 8 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Composite/CoffeeScript/API/Ball.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Toy = require './Toy' 4 | 5 | # ============================== 6 | # SIMPLE (CONCRETE) COMPONENT 7 | # ============================== 8 | 9 | # A ball does not contain anything 10 | class Ball extends Toy 11 | description: -> 12 | "There's a ball!\n" 13 | 14 | module.exports = Ball 15 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Composite/CoffeeScript/API/Toy.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # ABSTRACT COMPONENT 5 | # ============================== 6 | 7 | class Toy 8 | constructor: -> 9 | throw new Error "You cannot instantiate an abstract class!" if @constructor is Toy 10 | 11 | description: -> 12 | throw new Error "You cannot call an abstract method!" 13 | 14 | module.exports = Toy 15 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Composite/Composite.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Structural/Composite/Composite.dia -------------------------------------------------------------------------------- /GoF/classic/Structural/Composite/Composite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Structural/Composite/Composite.png -------------------------------------------------------------------------------- /GoF/classic/Structural/Composite/ECMAScript/ES6/API/Ball.js: -------------------------------------------------------------------------------- 1 | import Toy from './Toy'; 2 | 3 | // ============================== 4 | // SIMPLE (CONCRETE) COMPONENT 5 | // ============================== 6 | 7 | // A ball does not contain anything 8 | export default class Ball extends Toy { 9 | description() { 10 | return "There's a ball!\n"; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Composite/ECMAScript/ES6/API/Toy.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT COMPONENT 3 | // ============================== 4 | 5 | export default class Toy { 6 | constructor() { 7 | if (new.target !== undefined) { 8 | throw new Error("You cannot instantiate an abstract class!"); 9 | } 10 | } 11 | 12 | description() { 13 | throw new Error("You cannot call an abstract method!"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Composite/TypeScript/API/Ball.ts: -------------------------------------------------------------------------------- 1 | import Toy from './Toy'; 2 | 3 | // ============================== 4 | // SIMPLE (CONCRETE) COMPONENT 5 | // ============================== 6 | 7 | // A ball does not contain anything 8 | export default class Ball implements Toy { 9 | public description(): string { 10 | return "There's a ball!\n"; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Composite/TypeScript/API/Toy.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT COMPONENT 3 | // ============================== 4 | 5 | export default interface Toy { 6 | description(): string; 7 | } 8 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Decorator/CoffeeScript/API/Bacon.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | CustomPizza = require './CustomPizza' 4 | 5 | # ============================== 6 | # PIZZA INGREDIENT 7 | # ============================== 8 | 9 | class Bacon extends CustomPizza 10 | ingredients: -> 11 | "#{@_pizza.ingredients()}- Bacon\n" 12 | 13 | module.exports = Bacon 14 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Decorator/CoffeeScript/API/Margherita.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Pizza = require './Pizza' 4 | 5 | # ============================== 6 | # CONCRETE PIZZA 7 | # ============================== 8 | 9 | class Margherita extends Pizza 10 | ingredients: -> 11 | "- Tomatoes\n- Mozzarella\n" 12 | 13 | module.exports = Margherita 14 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Decorator/CoffeeScript/API/Peppers.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | CustomPizza = require './CustomPizza' 4 | 5 | # ============================== 6 | # PIZZA INGREDIENT 7 | # ============================== 8 | 9 | class Peppers extends CustomPizza 10 | ingredients: -> 11 | "#{@_pizza.ingredients()}- Peppers\n" 12 | 13 | module.exports = Peppers 14 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Decorator/CoffeeScript/API/Pizza.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # ABSTRACT PIZZA 5 | # ============================== 6 | 7 | class Pizza 8 | constructor: -> 9 | throw new Error "You cannot instantiate an abstract class!" if @constructor is Pizza 10 | 11 | ingredients: -> 12 | throw new Error "You cannot call an abstract method!" 13 | 14 | module.exports = Pizza 15 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Decorator/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Margherita = require './API/Margherita' 4 | Bacon = require './API/Bacon' 5 | Peppers = require './API/Peppers' 6 | 7 | # ============================== 8 | # CLIENT CODE 9 | # ============================== 10 | 11 | console.log new Peppers(new Bacon(new Margherita())).ingredients() 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Decorator/Decorator.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Structural/Decorator/Decorator.dia -------------------------------------------------------------------------------- /GoF/classic/Structural/Decorator/Decorator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Structural/Decorator/Decorator.png -------------------------------------------------------------------------------- /GoF/classic/Structural/Decorator/ECMAScript/ES5/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var Margherita = require('./API/Margherita'), 4 | Bacon = require('./API/Bacon'), 5 | Peppers = require('./API/Peppers'); 6 | 7 | // ============================== 8 | // CLIENT CODE 9 | // ============================== 10 | 11 | console.log(new Peppers(new Bacon(new Margherita())).ingredients()); 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Decorator/ECMAScript/ES6/API/Bacon.js: -------------------------------------------------------------------------------- 1 | import CustomPizza from './CustomPizza'; 2 | 3 | // ============================== 4 | // PIZZA INGREDIENT 5 | // ============================== 6 | 7 | export default class Bacon extends CustomPizza { 8 | ingredients() { 9 | return this._pizza.ingredients() + "- Bacon\n"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Decorator/ECMAScript/ES6/API/Margherita.js: -------------------------------------------------------------------------------- 1 | import Pizza from './Pizza'; 2 | 3 | // ============================== 4 | // CONCRETE PIZZA 5 | // ============================== 6 | 7 | export default class Margherita extends Pizza { 8 | ingredients() { 9 | return "- Tomatoes\n- Mozzarella\n"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Decorator/ECMAScript/ES6/API/Peppers.js: -------------------------------------------------------------------------------- 1 | import CustomPizza from './CustomPizza'; 2 | 3 | // ============================== 4 | // PIZZA INGREDIENT 5 | // ============================== 6 | 7 | export default class Peppers extends CustomPizza { 8 | ingredients() { 9 | return this._pizza.ingredients() + "- Peppers\n"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Decorator/ECMAScript/ES6/API/Pizza.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT PIZZA 3 | // ============================== 4 | 5 | export default class Pizza { 6 | constructor() { 7 | if (new.target !== undefined) { 8 | throw new Error("You cannot instantiate an abstract class!"); 9 | } 10 | } 11 | 12 | ingredients() { 13 | throw new Error("You cannot call an abstract method!"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Decorator/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import Margherita from './API/Margherita'; 2 | import Bacon from './API/Bacon'; 3 | import Peppers from './API/Peppers'; 4 | 5 | // ============================== 6 | // CLIENT CODE 7 | // ============================== 8 | 9 | console.log(new Peppers(new Bacon(new Margherita())).ingredients()); 10 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Decorator/TypeScript/API/Bacon.ts: -------------------------------------------------------------------------------- 1 | import CustomPizza from './CustomPizza'; 2 | 3 | // ============================== 4 | // PIZZA INGREDIENT 5 | // ============================== 6 | 7 | export default class Bacon extends CustomPizza { 8 | public ingredients(): string { 9 | return this.pizza.ingredients() + "- Bacon\n"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Decorator/TypeScript/API/Margherita.ts: -------------------------------------------------------------------------------- 1 | import Pizza from './Pizza'; 2 | 3 | // ============================== 4 | // CONCRETE PIZZA 5 | // ============================== 6 | 7 | export default class Margherita implements Pizza { 8 | public ingredients(): string { 9 | return "- Tomatoes\n- Mozzarella\n"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Decorator/TypeScript/API/Peppers.ts: -------------------------------------------------------------------------------- 1 | import CustomPizza from './CustomPizza'; 2 | 3 | // ============================== 4 | // PIZZA INGREDIENT 5 | // ============================== 6 | 7 | export default class Peppers extends CustomPizza { 8 | public ingredients(): string { 9 | return this.pizza.ingredients() + "- Peppers\n"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Decorator/TypeScript/API/Pizza.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT PIZZA 3 | // ============================== 4 | 5 | export default interface Pizza { 6 | ingredients(): string; 7 | } 8 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Decorator/TypeScript/client.ts: -------------------------------------------------------------------------------- 1 | import Margherita from './API/Margherita'; 2 | import Bacon from './API/Bacon'; 3 | import Peppers from './API/Peppers'; 4 | 5 | // ============================== 6 | // CLIENT CODE 7 | // ============================== 8 | 9 | console.log(new Peppers(new Bacon(new Margherita())).ingredients()); 10 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Facade/CoffeeScript/API/Animal.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # ABSTRACT ANIMAL 5 | # ============================== 6 | 7 | class Animal 8 | constructor: -> 9 | throw new Error "You cannot instantiate an abstract class!" if @constructor is Animal 10 | 11 | eat: -> 12 | throw new Error "You cannot call an abstract method!" 13 | 14 | module.exports = Animal 15 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Facade/CoffeeScript/API/Dog.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Animal = require './Animal' 4 | 5 | # ============================== 6 | # CONCRETE ANIMAL 7 | # ============================== 8 | 9 | class Dog extends Animal 10 | eat: -> 11 | "Dog: 'Meat, please!'\n" 12 | 13 | module.exports = Dog 14 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Facade/CoffeeScript/API/HowToFeedAnimals.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Dog = require './Dog' 4 | Rabbit = require './Rabbit' 5 | 6 | # ============================== 7 | # THE FACADE 8 | # ============================== 9 | 10 | class HowToFeedAnimals 11 | constructor: -> 12 | @_dog = new Dog 13 | @_rabbit = new Rabbit 14 | 15 | feedAnimals: -> 16 | "#{@_dog.eat()}#{@_rabbit.eat()}" 17 | 18 | module.exports = HowToFeedAnimals 19 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Facade/CoffeeScript/API/Rabbit.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | Animal = require './Animal' 4 | 5 | # ============================== 6 | # CONCRETE ANIMAL 7 | # ============================== 8 | 9 | class Rabbit extends Animal 10 | eat: -> 11 | "Rabbit: 'A carrot would be great!'\n" 12 | 13 | module.exports = Rabbit 14 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Facade/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | HowToFeedAnimals = require './API/HowToFeedAnimals' 4 | 5 | # ============================== 6 | # CLIENT CODE 7 | # ============================== 8 | 9 | facade = new HowToFeedAnimals 10 | 11 | console.log facade.feedAnimals() 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Facade/ECMAScript/ES5/API/Dog.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var Animal = require('./Animal'); 4 | 5 | // ============================== 6 | // CONCRETE ANIMAL 7 | // ============================== 8 | 9 | var Dog = function () {}; 10 | Dog.prototype = Object.create(Animal.prototype); 11 | Dog.prototype.constructor = Dog; 12 | 13 | Dog.prototype.eat = function () { 14 | return "Dog: 'Meat, please!'\n"; 15 | }; 16 | 17 | module.exports = Dog; 18 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Facade/ECMAScript/ES5/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var HowToFeedAnimals = require('./API/HowToFeedAnimals'); 4 | 5 | // ============================== 6 | // CLIENT CODE 7 | // ============================== 8 | 9 | var facade = new HowToFeedAnimals(); 10 | 11 | console.log(facade.feedAnimals()); 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Facade/ECMAScript/ES6/API/Animal.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT ANIMAL 3 | // ============================== 4 | 5 | export default class Animal { 6 | constructor() { 7 | if (new.target !== undefined) { 8 | throw new Error("You cannot instantiate an abstract class!"); 9 | } 10 | } 11 | 12 | eat() { 13 | throw new Error("You cannot call an abstract method!"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Facade/ECMAScript/ES6/API/Dog.js: -------------------------------------------------------------------------------- 1 | import Animal from './Animal'; 2 | 3 | // ============================== 4 | // CONCRETE ANIMAL 5 | // ============================== 6 | 7 | export default class Dog extends Animal { 8 | eat() { 9 | return "Dog: 'Meat, please!'\n"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Facade/ECMAScript/ES6/API/Rabbit.js: -------------------------------------------------------------------------------- 1 | import Animal from './Animal'; 2 | 3 | // ============================== 4 | // CONCRETE ANIMAL 5 | // ============================== 6 | 7 | export default class Rabbit extends Animal { 8 | eat() { 9 | return "Rabbit: 'A carrot would be great!'\n"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Facade/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import HowToFeedAnimals from './API/HowToFeedAnimals'; 2 | 3 | // ============================== 4 | // CLIENT CODE 5 | // ============================== 6 | 7 | let facade = new HowToFeedAnimals(); 8 | 9 | console.log(facade.feedAnimals()); 10 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Facade/Facade.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Structural/Facade/Facade.dia -------------------------------------------------------------------------------- /GoF/classic/Structural/Facade/Facade.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Structural/Facade/Facade.png -------------------------------------------------------------------------------- /GoF/classic/Structural/Facade/TypeScript/API/Animal.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT ANIMAL 3 | // ============================== 4 | 5 | export default interface Animal { 6 | eat(): string; 7 | } 8 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Facade/TypeScript/API/Dog.ts: -------------------------------------------------------------------------------- 1 | import Animal from './Animal'; 2 | 3 | // ============================== 4 | // CONCRETE ANIMAL 5 | // ============================== 6 | 7 | export default class Dog implements Animal { 8 | public eat(): string { 9 | return "Dog: 'Meat, please!'\n"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Facade/TypeScript/API/HowToFeedAnimals.ts: -------------------------------------------------------------------------------- 1 | import Dog from './Dog'; 2 | import Rabbit from './Rabbit'; 3 | 4 | // ============================== 5 | // THE FACADE 6 | // ============================== 7 | 8 | export default class HowToFeedAnimals { 9 | private dog: Dog = new Dog(); 10 | private rabbit: Rabbit = new Rabbit(); 11 | 12 | public feedAnimals(): string { 13 | return `${this.dog.eat()}${this.rabbit.eat()}`; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Facade/TypeScript/API/Rabbit.ts: -------------------------------------------------------------------------------- 1 | import Animal from './Animal'; 2 | 3 | // ============================== 4 | // CONCRETE ANIMAL 5 | // ============================== 6 | 7 | export default class Rabbit implements Animal { 8 | public eat(): string { 9 | return "Rabbit: 'A carrot would be great!'\n"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Facade/TypeScript/client.ts: -------------------------------------------------------------------------------- 1 | import HowToFeedAnimals from './API/HowToFeedAnimals'; 2 | 3 | // ============================== 4 | // CLIENT CODE 5 | // ============================== 6 | 7 | let facade: HowToFeedAnimals = new HowToFeedAnimals(); 8 | 9 | console.log(facade.feedAnimals()); 10 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Flyweight/CoffeeScript/API/Debian.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | LinuxDistro = require './LinuxDistro' 4 | 5 | # ============================== 6 | # CONCRETE GNU/LINUX DISTRO 7 | # ============================== 8 | 9 | class Debian extends LinuxDistro 10 | constructor: -> 11 | super "Debian" 12 | 13 | module.exports = Debian 14 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Flyweight/CoffeeScript/API/RedHat.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | LinuxDistro = require './LinuxDistro' 4 | 5 | # ============================== 6 | # CONCRETE GNU/LINUX DISTRO 7 | # ============================== 8 | 9 | class RedHat extends LinuxDistro 10 | constructor: -> 11 | super "RedHat" 12 | 13 | module.exports = RedHat 14 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Flyweight/CoffeeScript/API/Slackware.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | LinuxDistro = require './LinuxDistro' 4 | 5 | # ============================== 6 | # CONCRETE GNU/LINUX DISTRO 7 | # ============================== 8 | 9 | class Slackware extends LinuxDistro 10 | constructor: -> 11 | super "Slackware" 12 | 13 | module.exports = Slackware 14 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Flyweight/ECMAScript/ES5/API/Debian.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var LinuxDistro = require('./LinuxDistro'); 4 | 5 | // ============================== 6 | // CONCRETE GNU/LINUX DISTRO 7 | // ============================== 8 | 9 | var Debian = function () { 10 | LinuxDistro.call(this, "Debian"); 11 | } 12 | Debian.prototype = Object.create(LinuxDistro.prototype); 13 | Debian.prototype.constructor = Debian; 14 | 15 | module.exports = Debian; 16 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Flyweight/ECMAScript/ES5/API/RedHat.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var LinuxDistro = require('./LinuxDistro'); 4 | 5 | // ============================== 6 | // CONCRETE GNU/LINUX DISTRO 7 | // ============================== 8 | 9 | var RedHat = function () { 10 | LinuxDistro.call(this, "RedHat"); 11 | } 12 | RedHat.prototype = Object.create(LinuxDistro.prototype); 13 | RedHat.prototype.constructor = RedHat; 14 | 15 | module.exports = RedHat; 16 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Flyweight/ECMAScript/ES5/API/Slackware.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var LinuxDistro = require('./LinuxDistro'); 4 | 5 | // ============================== 6 | // CONCRETE GNU/LINUX DISTRO 7 | // ============================== 8 | 9 | var Slackware = function () { 10 | LinuxDistro.call(this, "Slackware"); 11 | } 12 | Slackware.prototype = Object.create(LinuxDistro.prototype); 13 | Slackware.prototype.constructor = Slackware; 14 | 15 | module.exports = Slackware; 16 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Flyweight/ECMAScript/ES6/API/Debian.js: -------------------------------------------------------------------------------- 1 | import LinuxDistro from './LinuxDistro'; 2 | 3 | // ============================== 4 | // CONCRETE GNU/LINUX DISTRO 5 | // ============================== 6 | 7 | export default class Debian extends LinuxDistro { 8 | constructor() { 9 | super(Debian.name); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Flyweight/ECMAScript/ES6/API/RedHat.js: -------------------------------------------------------------------------------- 1 | import LinuxDistro from './LinuxDistro'; 2 | 3 | // ============================== 4 | // CONCRETE GNU/LINUX DISTRO 5 | // ============================== 6 | 7 | export default class RedHat extends LinuxDistro { 8 | constructor() { 9 | super(RedHat.name); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Flyweight/ECMAScript/ES6/API/Slackware.js: -------------------------------------------------------------------------------- 1 | import LinuxDistro from './LinuxDistro'; 2 | 3 | // ============================== 4 | // CONCRETE GNU/LINUX DISTRO 5 | // ============================== 6 | 7 | export default class Slackware extends LinuxDistro { 8 | constructor() { 9 | super(Slackware.name); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Flyweight/Flyweight.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Structural/Flyweight/Flyweight.dia -------------------------------------------------------------------------------- /GoF/classic/Structural/Flyweight/Flyweight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Structural/Flyweight/Flyweight.png -------------------------------------------------------------------------------- /GoF/classic/Structural/Flyweight/TypeScript/API/Debian.ts: -------------------------------------------------------------------------------- 1 | import LinuxDistro from './LinuxDistro'; 2 | 3 | // ============================== 4 | // CONCRETE GNU/LINUX DISTRO 5 | // ============================== 6 | 7 | export default class Debian extends LinuxDistro { 8 | constructor() { 9 | super("Debian"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Flyweight/TypeScript/API/LinuxDistro.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT GNU/LINUX DISTRO 3 | // ============================== 4 | 5 | abstract class LinuxDistro { 6 | private name: string; 7 | 8 | constructor(name: string) { 9 | this.name = name; 10 | } 11 | 12 | public boot(): string { 13 | return `${this.name} is booting...`; 14 | } 15 | } 16 | 17 | export default LinuxDistro; 18 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Flyweight/TypeScript/API/RedHat.ts: -------------------------------------------------------------------------------- 1 | import LinuxDistro from './LinuxDistro'; 2 | 3 | // ============================== 4 | // CONCRETE GNU/LINUX DISTROS 5 | // ============================== 6 | 7 | export default class RedHat extends LinuxDistro { 8 | constructor() { 9 | super("RedHat"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Flyweight/TypeScript/API/Slackware.ts: -------------------------------------------------------------------------------- 1 | import LinuxDistro from './LinuxDistro'; 2 | 3 | // ============================== 4 | // CONCRETE GNU/LINUX DISTROS 5 | // ============================== 6 | 7 | export default class Slackware extends LinuxDistro { 8 | constructor() { 9 | super("Slackware"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Proxy/CoffeeScript/API/BankAccount.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | FinancialEntity = require './FinancialEntity' 4 | 5 | # ============================== 6 | # CONCRETE BANK ACCOUNT 7 | # ============================== 8 | 9 | class BankAccount extends FinancialEntity 10 | withdrawMoney: -> 11 | "Enjoy the cash!" 12 | 13 | module.exports = BankAccount 14 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Proxy/CoffeeScript/API/FinancialEntity.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # ABSTRACT FINANCIAL ENTITY 5 | # ============================== 6 | 7 | class FinancialEntity 8 | constructor: -> 9 | throw new Error "You cannot instantiate an abstract class!" if @constructor is FinancialEntity 10 | 11 | withdrawMoney: -> 12 | throw new Error "You cannot call an abstract method!" 13 | 14 | module.exports = FinancialEntity 15 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Proxy/ECMAScript/ES6/API/BankAccount.js: -------------------------------------------------------------------------------- 1 | import FinancialEntity from './FinancialEntity'; 2 | 3 | // ============================== 4 | // CONCRETE BANK ACCOUNT 5 | // ============================== 6 | 7 | export default class BankAccount extends FinancialEntity { 8 | withdrawMoney() { 9 | return "Enjoy the cash!"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Proxy/Proxy.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Structural/Proxy/Proxy.dia -------------------------------------------------------------------------------- /GoF/classic/Structural/Proxy/Proxy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/classic/Structural/Proxy/Proxy.png -------------------------------------------------------------------------------- /GoF/classic/Structural/Proxy/TypeScript/API/BankAccount.ts: -------------------------------------------------------------------------------- 1 | import FinancialEntity from './FinancialEntity'; 2 | 3 | // ============================== 4 | // CONCRETE BANK ACCOUNT 5 | // ============================== 6 | 7 | export default class BankAccount implements FinancialEntity { 8 | public withdrawMoney(code: number): string { 9 | return "Enjoy the cash!"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /GoF/classic/Structural/Proxy/TypeScript/API/FinancialEntity.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ABSTRACT FINANCIAL ENTITY 3 | // ============================== 4 | 5 | export default interface FinancialEntity { 6 | withdrawMoney(code: number): string; 7 | } 8 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/ChainOfResponsibility/ChainOfResponsibility.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Behavioral/ChainOfResponsibility/ChainOfResponsibility.dia -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/ChainOfResponsibility/ChainOfResponsibility.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Behavioral/ChainOfResponsibility/ChainOfResponsibility.png -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/ChainOfResponsibility/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | race = require './API/race' 4 | 5 | # ============================== 6 | # CLIENT CODE 7 | # ============================== 8 | 9 | race.walker.nextRelay = race.runner 10 | race.runner.nextRelay = race.swimmer 11 | 12 | console.log race.walker.go() 13 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/ChainOfResponsibility/ECMAScript/ES5/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var race = require('./API/race'); 4 | 5 | // ============================== 6 | // CLIENT CODE 7 | // ============================== 8 | 9 | race.walker.nextRelay = race.runner; 10 | race.runner.nextRelay = race.swimmer; 11 | 12 | console.log(race.walker.go()); 13 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/ChainOfResponsibility/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import { walker, runner, swimmer } from './API/race'; 2 | 3 | // ============================== 4 | // CLIENT CODE 5 | // ============================== 6 | 7 | walker.nextRelay = runner; 8 | runner.nextRelay = swimmer; 9 | 10 | console.log(walker.go()); 11 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/ChainOfResponsibility/TypeScript/client.ts: -------------------------------------------------------------------------------- 1 | import { walker, runner, swimmer } from './API/race'; 2 | 3 | // ============================== 4 | // CLIENT CODE 5 | // ============================== 6 | 7 | walker.nextRelay = runner; 8 | runner.nextRelay = swimmer; 9 | 10 | console.log(walker.go()); 11 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Command/CoffeeScript/API/customer.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # CUSTOMER 5 | # ============================== 6 | 7 | module.exports = 8 | pay: -> 9 | "Payment OK!\n" 10 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Command/CoffeeScript/API/order.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # ORDER 5 | # ============================== 6 | 7 | module.exports = 8 | deliver: -> 9 | @customer.pay() 10 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Command/CoffeeScript/API/restaurant.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # RESTAURANT 5 | # ============================== 6 | 7 | module.exports = 8 | orders: [] 9 | addOrder: (order) -> 10 | @orders.push order 11 | prepareOrders: -> 12 | summary = "" 13 | summary += order.deliver() for order in @orders 14 | summary 15 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Command/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | texMex = require './API/order'; 4 | restaurant = require './API/restaurant'; 5 | customer = require './API/customer'; 6 | 7 | # ============================== 8 | # CLIENT CODE 9 | # ============================== 10 | 11 | texMex.customer = customer 12 | restaurant.addOrder texMex 13 | 14 | console.log restaurant.prepareOrders() 15 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Command/Command.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Behavioral/Command/Command.dia -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Command/Command.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Behavioral/Command/Command.png -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Command/ECMAScript/ES5/API/customer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // ============================== 4 | // CUSTOMER 5 | // ============================== 6 | 7 | module.exports = { 8 | pay: function () { 9 | return "Payment OK!\n"; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Command/ECMAScript/ES5/API/order.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // ============================== 4 | // ORDER 5 | // ============================== 6 | 7 | module.exports = { 8 | deliver: function () { 9 | return this.customer.pay(); 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Command/ECMAScript/ES5/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var texMex = require('./API/order'), 4 | restaurant = require('./API/restaurant'), 5 | customer = require('./API/customer'); 6 | 7 | // ============================== 8 | // CLIENT CODE 9 | // ============================== 10 | 11 | texMex.customer = customer; 12 | restaurant.addOrder(texMex); 13 | 14 | console.log(restaurant.prepareOrders()); 15 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Command/ECMAScript/ES6/API/customer.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // CUSTOMER 3 | // ============================== 4 | 5 | export default { 6 | pay() { 7 | return "Payment OK!\n"; 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Command/ECMAScript/ES6/API/order.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ORDER 3 | // ============================== 4 | 5 | export default { 6 | deliver() { 7 | return this.customer.pay(); 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Command/ECMAScript/ES6/API/restaurant.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // RESTAURANT 3 | // ============================== 4 | 5 | export default { 6 | orders: [], 7 | addOrder(order) { 8 | this.orders.push(order); 9 | }, 10 | prepareOrders() { 11 | let summary = ""; 12 | for (let order of this.orders) { 13 | summary += order.deliver(); 14 | } 15 | return summary; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Command/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import texMex from './API/order'; 2 | import restaurant from './API/restaurant'; 3 | import customer from './API/customer'; 4 | 5 | // ============================== 6 | // CLIENT CODE 7 | // ============================== 8 | 9 | texMex.customer = customer; 10 | restaurant.addOrder(texMex); 11 | 12 | console.log(restaurant.prepareOrders()); 13 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Command/TypeScript/API/customer.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // CUSTOMER 3 | // ============================== 4 | 5 | export interface Customer { 6 | pay(): string; 7 | } 8 | 9 | export const customer: Customer = { 10 | pay() { 11 | return "Payment OK!\n"; 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Command/TypeScript/API/order.ts: -------------------------------------------------------------------------------- 1 | import { Customer } from './customer'; 2 | 3 | // ============================== 4 | // ORDER 5 | // ============================== 6 | 7 | export interface Order { 8 | customer?: Customer; 9 | deliver(): string; 10 | } 11 | 12 | export const texMex: Order = { 13 | deliver() { 14 | return this.customer.pay(); 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Command/TypeScript/client.ts: -------------------------------------------------------------------------------- 1 | import { texMex } from './API/order'; 2 | import { restaurant } from './API/restaurant'; 3 | import { customer } from './API/customer'; 4 | 5 | // ============================== 6 | // CLIENT CODE 7 | // ============================== 8 | 9 | texMex.customer = customer; 10 | restaurant.addOrder(texMex); 11 | 12 | console.log(restaurant.prepareOrders()); 13 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Interpreter/CoffeeScript/API/context.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # CONTEXT (SONATA) 5 | # ============================== 6 | 7 | module.exports = 8 | name: "Moonlight Sonata" 9 | composer: "Beethoven" 10 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Interpreter/ECMAScript/ES5/API/context.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // ============================== 4 | // CONTEXT (SONATA) 5 | // ============================== 6 | 7 | module.exports = { 8 | name: "Moonlight Sonata", 9 | composer: "Beethoven" 10 | }; 11 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Interpreter/ECMAScript/ES6/API/context.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // CONTEXT (SONATA) 3 | // ============================== 4 | 5 | export default { 6 | name: "Moonlight Sonata", 7 | composer: "Beethoven" 8 | }; 9 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Interpreter/Interpreter.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Behavioral/Interpreter/Interpreter.dia -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Interpreter/Interpreter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Behavioral/Interpreter/Interpreter.png -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Interpreter/TypeScript/API/context.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // CONTEXT (SONATA) 3 | // ============================== 4 | 5 | export interface Sonata { 6 | name: string; 7 | composer: string; 8 | } 9 | 10 | export const sonata: Sonata = { 11 | name: "Moonlight Sonata", 12 | composer: "Beethoven" 13 | }; 14 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Iterator/CoffeeScript/API/iterable.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # ITERABLE (LIBRARY) 5 | # ============================== 6 | 7 | module.exports = 8 | books: [] 9 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Iterator/CoffeeScript/API/iterator.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # ITERATOR (CATALOG) 5 | # ============================== 6 | 7 | module.exports = 8 | index: 0 9 | hasNext: -> 10 | @index < @collection.books.length 11 | next: -> 12 | @collection.books[@index++] 13 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Iterator/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | library = require './API/iterable' 4 | catalog = require './API/iterator' 5 | 6 | # ============================== 7 | # CLIENT CODE 8 | # ============================== 9 | 10 | library.books = ["Foo", "Bar"] 11 | catalog.collection = library 12 | 13 | console.log catalog.next() while catalog.hasNext() 14 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Iterator/ECMAScript/ES5/API/iterable.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // ============================== 4 | // ITERABLE (LIBRARY) 5 | // ============================== 6 | 7 | module.exports = { 8 | books: [] 9 | }; 10 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Iterator/ECMAScript/ES5/API/iterator.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // ============================== 4 | // ITERATOR (CATALOG) 5 | // ============================== 6 | 7 | module.exports = { 8 | index: 0, 9 | hasNext: function () { 10 | return this.index < this.collection.books.length; 11 | }, 12 | next: function () { 13 | return this.collection.books[this.index++]; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Iterator/ECMAScript/ES5/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var library = require('./API/iterable'), 4 | catalog = require('./API/iterator'); 5 | 6 | // ============================== 7 | // CLIENT CODE 8 | // ============================== 9 | 10 | library.books = ["Foo", "Bar"]; 11 | catalog.collection = library; 12 | 13 | while (catalog.hasNext()) { 14 | console.log(catalog.next()); 15 | } 16 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Iterator/ECMAScript/ES6/API/iterable.js: -------------------------------------------------------------------------------- 1 | import catalog from './iterator'; 2 | 3 | // ============================== 4 | // ITERABLE (LIBRARY) 5 | // ============================== 6 | 7 | export default { 8 | books: [], 9 | [Symbol.iterator]() { 10 | return catalog; 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Iterator/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import library from './API/iterable'; 2 | import catalog from './API/iterator'; 3 | 4 | // ============================== 5 | // CLIENT CODE 6 | // ============================== 7 | 8 | library.books = ["Foo", "Bar"]; 9 | catalog.collection = library; 10 | 11 | for (let book of library) { 12 | console.log(book); 13 | } 14 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Iterator/Iterator.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Behavioral/Iterator/Iterator.dia -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Iterator/Iterator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Behavioral/Iterator/Iterator.png -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Iterator/TypeScript/API/iterable.ts: -------------------------------------------------------------------------------- 1 | import { Catalog, catalog } from './iterator'; 2 | 3 | // ============================== 4 | // ITERABLE (LIBRARY) 5 | // ============================== 6 | 7 | export interface Library { 8 | books: string[]; 9 | [Symbol.iterator](): Catalog; 10 | } 11 | 12 | export const library: Library = { 13 | books: [], 14 | [Symbol.iterator]() { 15 | return catalog; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Iterator/TypeScript/client.ts: -------------------------------------------------------------------------------- 1 | import { catalog } from './API/iterator'; 2 | import { library } from './API/iterable'; 3 | 4 | // ============================== 5 | // CLIENT CODE 6 | // ============================== 7 | 8 | library.books = ["Foo", "Bar"]; 9 | catalog.collection = library; 10 | 11 | for (let book of library) { 12 | console.log(book); 13 | } 14 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Mediator/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import { tom, dick } from './API/colleagues'; 2 | import harry from './API/mediator'; 3 | 4 | // ============================== 5 | // CLIENT CODE 6 | // ============================== 7 | 8 | let conversation = ""; 9 | conversation += tom.send("Could you lower the volume of your music, please?", harry); 10 | conversation += dick.send("Are you serious? The volume is actually very low...", harry); 11 | 12 | console.log(conversation); 13 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Mediator/Mediator.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Behavioral/Mediator/Mediator.dia -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Mediator/Mediator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Behavioral/Mediator/Mediator.png -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Mediator/TypeScript/client.ts: -------------------------------------------------------------------------------- 1 | import { tom, dick } from './API/colleagues'; 2 | import { harry } from './API/mediator'; 3 | 4 | // ============================== 5 | // CLIENT CODE 6 | // ============================== 7 | 8 | let conversation = ""; 9 | conversation += tom.send("Could you lower the volume of your music, please?", harry); 10 | conversation += dick.send("Are you serious? The volume is actually very low...", harry); 11 | 12 | console.log(conversation); 13 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Memento/CoffeeScript/API/bookmarks.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # CARETAKER (BOOKMARKS MANAGER) 5 | # ============================== 6 | 7 | module.exports = 8 | bookmarks: [] 9 | addBookmark: (bookmark) -> 10 | @bookmarks.push bookmark 11 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Memento/CoffeeScript/API/browser.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # ORIGINATOR (BROWSER) & MEMENTO (BOOKMARK) 5 | # ============================== 6 | 7 | module.exports = 8 | saveCurrentPage: -> 9 | webpage: @currentPage 10 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Memento/ECMAScript/ES5/API/bookmarks.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // ============================== 4 | // CARETAKER (BOOKMARKS MANAGER) 5 | // ============================== 6 | 7 | module.exports = { 8 | bookmarks: [], 9 | addBookmark: function (bookmark) { 10 | this.bookmarks.push(bookmark); 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Memento/ECMAScript/ES5/API/browser.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // ============================== 4 | // ORIGINATOR (BROWSER) & MEMENTO (BOOKMARK) 5 | // ============================== 6 | 7 | module.exports = { 8 | saveCurrentPage: function () { 9 | return { 10 | webpage: this.currentPage 11 | }; 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Memento/ECMAScript/ES6/API/bookmarks.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // CARETAKER (BOOKMARKS MANAGER) 3 | // ============================== 4 | 5 | export default { 6 | bookmarks: [], 7 | addBookmark(bookmark) { 8 | this.bookmarks.push(bookmark); 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Memento/ECMAScript/ES6/API/browser.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ORIGINATOR (BROWSER) & MEMENTO (BOOKMARK) 3 | // ============================== 4 | 5 | export default { 6 | saveCurrentPage() { 7 | return { 8 | webpage: this.currentPage 9 | } 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Memento/Memento.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Behavioral/Memento/Memento.dia -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Memento/Memento.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Behavioral/Memento/Memento.png -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Observer/CoffeeScript/API/observable.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # OBSERVABLE (GAZELLE) 5 | # ============================== 6 | 7 | module.exports = 8 | predators: [] 9 | addPredator: (predator) -> 10 | @predators.push predator 11 | notifyPredators: -> 12 | situation = "" 13 | situation += predator.attack() for predator in @predators 14 | situation 15 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Observer/CoffeeScript/API/observers.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # OBSERVERS (PREDATORS) 5 | # ============================== 6 | 7 | lion = 8 | attack: -> 9 | "Lion attack!\n" 10 | 11 | crocodile = 12 | attack: -> 13 | "Crocodile attack!\n" 14 | 15 | module.exports = 16 | lion: lion 17 | crocodile: crocodile 18 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Observer/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | predators = require './API/observers' 4 | gazelle = require './API/observable' 5 | 6 | # ============================== 7 | # CLIENT CODE 8 | # ============================== 9 | 10 | gazelle.addPredator predators.lion 11 | gazelle.addPredator predators.crocodile 12 | 13 | console.log gazelle.notifyPredators() 14 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Observer/ECMAScript/ES5/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var predators = require('./API/observers'), 4 | gazelle = require('./API/observable'); 5 | 6 | // ============================== 7 | // CLIENT CODE 8 | // ============================== 9 | 10 | gazelle.addPredator(predators.lion); 11 | gazelle.addPredator(predators.crocodile); 12 | 13 | console.log(gazelle.notifyPredators()); 14 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Observer/ECMAScript/ES6/API/observers.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // OBSERVERS (PREDATORS) 3 | // ============================== 4 | 5 | export const lion = { 6 | attack() { 7 | return "Lion attack!\n"; 8 | } 9 | }; 10 | 11 | export const crocodile = { 12 | attack() { 13 | return "Crocodile attack!\n"; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Observer/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import { lion, crocodile } from './API/observers'; 2 | import gazelle from './API/observable'; 3 | 4 | // ============================== 5 | // CLIENT CODE 6 | // ============================== 7 | 8 | gazelle.addPredator(lion); 9 | gazelle.addPredator(crocodile); 10 | 11 | console.log(gazelle.notifyPredators()); 12 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Observer/Observer.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Behavioral/Observer/Observer.dia -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Observer/Observer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Behavioral/Observer/Observer.png -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Observer/TypeScript/API/observers.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // OBSERVERS (PREDATORS) 3 | // ============================== 4 | 5 | export interface Predator { 6 | attack(): string; 7 | } 8 | 9 | export const lion: Predator = { 10 | attack() { 11 | return "Lion attack!\n"; 12 | } 13 | }; 14 | 15 | export const crocodile: Predator = { 16 | attack() { 17 | return "Crocodile attack!\n"; 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Observer/TypeScript/client.ts: -------------------------------------------------------------------------------- 1 | import { lion, crocodile } from './API/observers'; 2 | import { gazelle } from './API/observable'; 3 | 4 | // ============================== 5 | // CLIENT CODE 6 | // ============================== 7 | 8 | gazelle.addPredator(lion); 9 | gazelle.addPredator(crocodile); 10 | 11 | console.log(gazelle.notifyPredators()); 12 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/State/CoffeeScript/API/context.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | power = require './states' 4 | 5 | # ============================== 6 | # CONTEXT (PC) 7 | # ============================== 8 | 9 | module.exports = 10 | currentState: null 11 | states: 12 | OFF: power.OFF 13 | ON: power.ON 14 | power: -> 15 | @currentState.power(@) 16 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/State/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | pc = require './API/context' 4 | 5 | # ============================== 6 | # CLIENT CODE 7 | # ============================== 8 | 9 | pc.currentState = pc.states.OFF 10 | 11 | console.log pc.currentState.name # off 12 | pc.power() 13 | console.log pc.currentState.name # on 14 | pc.power() 15 | console.log pc.currentState.name # off 16 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/State/ECMAScript/ES5/API/context.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var power = require('./states'); 4 | 5 | // ============================== 6 | // CONTEXT (PC) 7 | // ============================== 8 | 9 | module.exports = { 10 | currentState: null, 11 | states: { 12 | off: power.off, 13 | on: power.on 14 | }, 15 | power: function () { 16 | this.currentState.power(this); 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/State/ECMAScript/ES5/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var pc = require('./API/context'); 4 | 5 | // ============================== 6 | // CLIENT CODE 7 | // ============================== 8 | 9 | pc.currentState = pc.states.off; 10 | 11 | console.log(pc.currentState.name); // off 12 | pc.power(); 13 | console.log(pc.currentState.name); // on 14 | pc.power(); 15 | console.log(pc.currentState.name); // off 16 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/State/ECMAScript/ES6/API/context.js: -------------------------------------------------------------------------------- 1 | import { off, on } from './states'; 2 | 3 | // ============================== 4 | // CONTEXT (PC) 5 | // ============================== 6 | 7 | export default { 8 | currentState: null, 9 | states: { off, on }, 10 | power() { 11 | this.currentState.power(this); 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/State/ECMAScript/ES6/API/states.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // STATES 3 | // ============================== 4 | 5 | export const off = { 6 | name: "off", 7 | power(pc) { 8 | pc.currentState = pc.states.on; 9 | } 10 | }; 11 | 12 | export const on = { 13 | name: "on", 14 | power(pc) { 15 | pc.currentState = pc.states.off; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/State/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import pc from './API/context'; 2 | 3 | // ============================== 4 | // CLIENT CODE 5 | // ============================== 6 | 7 | pc.currentState = pc.states.off; 8 | 9 | console.log(pc.currentState.name); // off 10 | pc.power(); 11 | console.log(pc.currentState.name); // on 12 | pc.power(); 13 | console.log(pc.currentState.name); // off 14 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/State/State.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Behavioral/State/State.dia -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/State/State.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Behavioral/State/State.png -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/State/TypeScript/client.ts: -------------------------------------------------------------------------------- 1 | import { pc } from './API/context'; 2 | 3 | // ============================== 4 | // CLIENT CODE 5 | // ============================== 6 | 7 | pc.currentState = pc.states.off; 8 | 9 | console.log(pc.currentState.name); // off 10 | pc.power(); 11 | console.log(pc.currentState.name); // on 12 | pc.power(); 13 | console.log(pc.currentState.name); // off 14 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Strategy/CoffeeScript/API/context.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # CONTEXT (FIGHTING GAME) 5 | # ============================== 6 | 7 | module.exports = 8 | strategy: null 9 | play: -> 10 | @strategy.fight() 11 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Strategy/CoffeeScript/API/strategies.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # STRATEGIES 5 | # ============================== 6 | 7 | offense = 8 | fight: -> 9 | "Fight with an offensive style" 10 | 11 | defense = 12 | fight: -> 13 | "Fight with a defensive style" 14 | 15 | module.exports = 16 | offense: offense 17 | defense: defense 18 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Strategy/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | fightingGame = require './API/context' 4 | strategies = require './API/strategies' 5 | 6 | # ============================== 7 | # CLIENT CODE 8 | # ============================== 9 | 10 | fightingGame.strategy = strategies.defense 11 | console.log "ROUND 1 - #{fightingGame.play()}" 12 | fightingGame.strategy = strategies.offense 13 | console.log "ROUND 2 - #{fightingGame.play()}" 14 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Strategy/ECMAScript/ES5/API/context.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // ============================== 4 | // CONTEXT (FIGHTING GAME) 5 | // ============================== 6 | 7 | module.exports = { 8 | strategy: null, 9 | play: function () { 10 | return this.strategy.fight(); 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Strategy/ECMAScript/ES5/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var fightingGame = require('./API/context'), 4 | strategies = require('./API/strategies'); 5 | 6 | // ============================== 7 | // CLIENT CODE 8 | // ============================== 9 | 10 | fightingGame.strategy = strategies.defense; 11 | console.log("ROUND 1 - " + fightingGame.play()); 12 | fightingGame.strategy = strategies.offense; 13 | console.log("ROUND 2 - " + fightingGame.play()); 14 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Strategy/ECMAScript/ES6/API/context.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // CONTEXT (FIGHTING GAME) 3 | // ============================== 4 | 5 | export default { 6 | strategy: null, 7 | play() { 8 | return this.strategy.fight(); 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Strategy/ECMAScript/ES6/API/strategies.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // STRATEGIES 3 | // ============================== 4 | 5 | export const offense = { 6 | fight() { 7 | return "Fight with an offensive style"; 8 | } 9 | }; 10 | 11 | export const defense = { 12 | fight() { 13 | return "Fight with a defensive style"; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Strategy/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import fightingGame from './API/context'; 2 | import { offense, defense } from './API/strategies'; 3 | 4 | // ============================== 5 | // CLIENT CODE 6 | // ============================== 7 | 8 | fightingGame.strategy = defense; 9 | console.log("ROUND 1 - " + fightingGame.play()); 10 | fightingGame.strategy = offense; 11 | console.log("ROUND 2 - " + fightingGame.play()); 12 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Strategy/Strategy.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Behavioral/Strategy/Strategy.dia -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Strategy/Strategy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Behavioral/Strategy/Strategy.png -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Strategy/TypeScript/API/context.ts: -------------------------------------------------------------------------------- 1 | import { Strategy } from './strategies'; 2 | 3 | // ============================== 4 | // CONTEXT (FIGHTING GAME) 5 | // ============================== 6 | 7 | export interface Game { 8 | strategy: Strategy; 9 | play(): string; 10 | } 11 | 12 | export const fightingGame: Game = { 13 | strategy: null, 14 | play() { 15 | return this.strategy.fight(); 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Strategy/TypeScript/API/strategies.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // STRATEGIES 3 | // ============================== 4 | 5 | export interface Strategy { 6 | fight(): string; 7 | } 8 | 9 | export const offense: Strategy = { 10 | fight() { 11 | return "Fight with an offensive style"; 12 | } 13 | }; 14 | 15 | export const defense: Strategy = { 16 | fight() { 17 | return "Fight with a defensive style"; 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Strategy/TypeScript/client.ts: -------------------------------------------------------------------------------- 1 | import { fightingGame } from './API/context'; 2 | import { offense, defense } from './API/strategies'; 3 | 4 | // ============================== 5 | // CLIENT CODE 6 | // ============================== 7 | 8 | fightingGame.strategy = defense; 9 | console.log("ROUND 1 - " + fightingGame.play()); 10 | fightingGame.strategy = offense; 11 | console.log("ROUND 2 - " + fightingGame.play()); 12 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Template/CoffeeScript/API/template.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # TEMPLATE METHOD 5 | # ============================== 6 | 7 | module.exports = (construction) -> 8 | """ 9 | Construction of a new home: 10 | 1. #{construction.foundations()} 11 | 2. #{construction.walls()} 12 | 3. #{construction.roof()}\n 13 | """ 14 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Template/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | build = require './API/template' 4 | homes = require './API/homes' 5 | 6 | # ============================== 7 | # CLIENT CODE 8 | # ============================== 9 | 10 | console.log build homes.house 11 | console.log build homes.building 12 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Template/ECMAScript/ES5/API/template.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // ============================== 4 | // TEMPLATE METHOD 5 | // ============================== 6 | 7 | module.exports = function (construction) { 8 | var home = ""; 9 | home += "Construction of a new home:\n"; 10 | home += " 1. " + construction.foundations(); 11 | home += " 2. " + construction.walls(); 12 | home += " 3. " + construction.roof(); 13 | return home; 14 | }; 15 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Template/ECMAScript/ES5/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var build = require('./API/template'), 4 | homes = require('./API/homes'); 5 | 6 | // ============================== 7 | // CLIENT CODE 8 | // ============================== 9 | 10 | console.log(build(homes.house)); 11 | console.log(build(homes.building)); 12 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Template/ECMAScript/ES6/API/template.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // TEMPLATE METHOD 3 | // ============================== 4 | 5 | export default construction => `Construction of a new home: 6 | 1. ${construction.foundations()} 7 | 2. ${construction.walls()} 8 | 3. ${construction.roof()} 9 | `; 10 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Template/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import build from './API/template'; 2 | import { house, building } from './API/homes'; 3 | 4 | // ============================== 5 | // CLIENT CODE 6 | // ============================== 7 | 8 | console.log(build(house)); 9 | console.log(build(building)); 10 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Template/Template.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Behavioral/Template/Template.dia -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Template/Template.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Behavioral/Template/Template.png -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Template/TypeScript/API/template.ts: -------------------------------------------------------------------------------- 1 | import { Home } from './homes'; 2 | 3 | // ============================== 4 | // TEMPLATE METHOD 5 | // ============================== 6 | 7 | export default (construction: Home): string => { 8 | return `Construction of a new home: 9 | 1. ${construction.foundations()} 10 | 2. ${construction.walls()} 11 | 3. ${construction.roof()} 12 | `}; 13 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Template/TypeScript/client.ts: -------------------------------------------------------------------------------- 1 | import build from './API/template'; 2 | import { house, building } from './API/homes'; 3 | 4 | // ============================== 5 | // CLIENT CODE 6 | // ============================== 7 | 8 | console.log(build(house)); 9 | console.log(build(building)); 10 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Visitor/CoffeeScript/API/monuments.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # MONUMENTS 5 | # ============================== 6 | 7 | module.exports = (name) -> 8 | name: name 9 | accept: (visitor) -> 10 | visitor.visit @ 11 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Visitor/CoffeeScript/API/visitor.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # VISITOR (TOURIST) 5 | # ============================== 6 | 7 | module.exports = 8 | visit: (monument) -> 9 | "Visiting #{monument.name}" 10 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Visitor/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | monument = require './API/monuments' 4 | tourist = require './API/visitor' 5 | 6 | # ============================== 7 | # CLIENT CODE 8 | # ============================== 9 | 10 | castle = monument 'Castle' 11 | abbey = monument 'Abbey' 12 | 13 | console.log castle.accept tourist 14 | console.log abbey.accept tourist 15 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Visitor/ECMAScript/ES5/API/monuments.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // ============================== 4 | // MONUMENTS 5 | // ============================== 6 | 7 | module.exports = function (name) { 8 | return { 9 | name: name, 10 | accept: function (visitor) { 11 | return visitor.visit(this); 12 | } 13 | } 14 | }; 15 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Visitor/ECMAScript/ES5/API/visitor.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // ============================== 4 | // VISITOR (TOURIST) 5 | // ============================== 6 | 7 | module.exports = { 8 | visit: function (monument) { 9 | return "Visiting " + monument.name; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Visitor/ECMAScript/ES5/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var monument = require('./API/monuments'), 4 | tourist = require('./API/visitor'); 5 | 6 | // ============================== 7 | // CLIENT CODE 8 | // ============================== 9 | 10 | var castle = monument('Castle'), 11 | abbey = monument('Abbey'); 12 | 13 | console.log(castle.accept(tourist)); 14 | console.log(abbey.accept(tourist)); 15 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Visitor/ECMAScript/ES6/API/monuments.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // MONUMENTS 3 | // ============================== 4 | 5 | export default name => { 6 | return { 7 | name: name, 8 | accept(visitor) { 9 | return visitor.visit(this); 10 | } 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Visitor/ECMAScript/ES6/API/visitor.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // VISITOR (TOURIST) 3 | // ============================== 4 | 5 | export default { 6 | visit(monument) { 7 | return `Visiting ${monument.name}`; 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Visitor/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import monument from './API/monuments'; 2 | import tourist from './API/visitor'; 3 | 4 | // ============================== 5 | // CLIENT CODE 6 | // ============================== 7 | 8 | let castle = monument('Castle'), 9 | abbey = monument('Abbey'); 10 | 11 | console.log(castle.accept(tourist)); 12 | console.log(abbey.accept(tourist)); 13 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Visitor/TypeScript/API/visitor.ts: -------------------------------------------------------------------------------- 1 | import { Monument } from './monuments'; 2 | 3 | // ============================== 4 | // VISITOR (TOURIST) 5 | // ============================== 6 | 7 | export interface Visitor { 8 | visit(monument: Monument): string; 9 | } 10 | 11 | export const tourist: Visitor = { 12 | visit(monument) { 13 | return `Visiting ${monument.name}`; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Visitor/TypeScript/client.ts: -------------------------------------------------------------------------------- 1 | import { monument } from './API/monuments'; 2 | import { tourist } from './API/visitor'; 3 | 4 | // ============================== 5 | // CLIENT CODE 6 | // ============================== 7 | 8 | let castle = monument('Castle'), 9 | abbey = monument('Abbey'); 10 | 11 | console.log(castle.accept(tourist)); 12 | console.log(abbey.accept(tourist)); 13 | -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Visitor/Visitor.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Behavioral/Visitor/Visitor.dia -------------------------------------------------------------------------------- /GoF/idiomatic/Behavioral/Visitor/Visitor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Behavioral/Visitor/Visitor.png -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/AbstractFactory/AbstractFactory.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Creational/AbstractFactory/AbstractFactory.dia -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/AbstractFactory/AbstractFactory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Creational/AbstractFactory/AbstractFactory.png -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/Builder/Builder.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Creational/Builder/Builder.dia -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/Builder/Builder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Creational/Builder/Builder.png -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/Builder/CoffeeScript/API/pc.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # PC (PRODUCT) 5 | # ============================== 6 | 7 | module.exports = 8 | toString: -> 9 | """ 10 | Motherboard: #{@motherboard} 11 | CPU: #{@cpu} 12 | RAM: #{@ram} 13 | SSD: #{@ssd} 14 | NIC: #{@nic} 15 | Power supply: #{@powerSupply} 16 | Case design: #{@caseDesign} 17 | """ 18 | -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/Builder/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | manufacturer = require './API/manufacturer' 4 | geek = require './API/builder' 5 | 6 | # ============================== 7 | # CLIENT CODE 8 | # ============================== 9 | 10 | myPc = manufacturer.manufacture geek 11 | 12 | console.log myPc 13 | -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/Builder/ECMAScript/ES5/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var manufacturer = require('./API/manufacturer'), 4 | geek = require('./API/builder'); 5 | 6 | // ============================== 7 | // CLIENT CODE 8 | // ============================== 9 | 10 | var myPc = manufacturer.manufacture(geek); 11 | 12 | console.log(myPc); 13 | -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/Builder/ECMAScript/ES6/API/pc.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // PC (PRODUCT) 3 | // ============================== 4 | 5 | export default { 6 | toString() { 7 | return `Motherboard: ${this.motherboard} 8 | CPU: ${this.cpu} 9 | RAM: ${this.ram} 10 | SSD: ${this.ssd} 11 | NIC: ${this.nic} 12 | Power supply: ${this.powerSupply} 13 | Case design: ${this.caseDesign}` 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/Builder/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import manufacturer from './API/manufacturer'; 2 | import geek from './API/builder'; 3 | 4 | // ============================== 5 | // CLIENT CODE 6 | // ============================== 7 | 8 | let myPc = manufacturer.manufacture(geek); 9 | 10 | console.log(myPc); 11 | -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/Builder/TypeScript/client.ts: -------------------------------------------------------------------------------- 1 | import { manufacturer } from './API/manufacturer'; 2 | import { geek } from './API/builder'; 3 | 4 | // ============================== 5 | // CLIENT CODE 6 | // ============================== 7 | 8 | let myPc: string = manufacturer.manufacture(geek); 9 | 10 | console.log(myPc); 11 | -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/Factory/Factory.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Creational/Factory/Factory.dia -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/Factory/Factory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Creational/Factory/Factory.png -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/Prototype/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | photocopy = require './API/photocopy' 4 | 5 | # ============================== 6 | # CLIENT CODE 7 | # ============================== 8 | 9 | invoice = 10 | price: 42 11 | currency: "€" 12 | 13 | copy = photocopy invoice 14 | 15 | console.log copy.price # 42 16 | console.log copy.currency # € 17 | console.log copy is invoice # false (the copy is not the original invoice: it is a new object!) 18 | -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/Prototype/ECMAScript/ES6/API/photocopy.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // PROTOTYPE 3 | // ============================== 4 | 5 | export default invoice => Object.assign(Object.create(Object.getPrototypeOf(invoice)), invoice); 6 | -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/Prototype/Prototype.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Creational/Prototype/Prototype.dia -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/Prototype/Prototype.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Creational/Prototype/Prototype.png -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/Prototype/TypeScript/API/photocopy.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // PROTOTYPE 3 | // ============================== 4 | 5 | export interface PaperSheet { 6 | price: number; 7 | currency: string; 8 | } 9 | 10 | export const photocopy: (invoice: PaperSheet) => PaperSheet = 11 | function (invoice: PaperSheet): PaperSheet { 12 | return Object.assign(Object.create(Object.getPrototypeOf(invoice)), invoice); 13 | }; 14 | -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/Singleton/CoffeeScript/API/me.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # SINGLETON: "ME" 5 | # ============================== 6 | 7 | module.exports = 8 | firstName: "Baptiste" 9 | lastName: "Vannesson" 10 | -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/Singleton/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | me = require './API/me' 4 | meAgain = require './API/me' 5 | 6 | # ============================== 7 | # CLIENT CODE 8 | # ============================== 9 | 10 | # It will display 'OK' since 'me' and 'meAgain' are references to the same object. 11 | # Only one instance exists in the code. This is what we expect from a Singleton. :) 12 | if me is meAgain then console.log "OK" else console.log "KO" 13 | -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/Singleton/ECMAScript/ES5/API/me.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // ============================== 4 | // SINGLETON: "ME" 5 | // ============================== 6 | 7 | module.exports = { 8 | firstName: "Baptiste", 9 | lastName: "Vannesson" 10 | }; 11 | -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/Singleton/ECMAScript/ES6/API/me.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // SINGLETON: "ME" 3 | // ============================== 4 | 5 | export default { 6 | firstName: "Baptiste", 7 | lastName: "Vannesson" 8 | }; 9 | -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/Singleton/Singleton.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Creational/Singleton/Singleton.dia -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/Singleton/Singleton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Creational/Singleton/Singleton.png -------------------------------------------------------------------------------- /GoF/idiomatic/Creational/Singleton/TypeScript/API/me.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // SINGLETON: "ME" 3 | // ============================== 4 | 5 | export interface Me { 6 | firstName: string; 7 | lastName: string; 8 | } 9 | 10 | export const me: Me = { 11 | firstName: "Baptiste", 12 | lastName: "Vannesson" 13 | }; 14 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Adapter/Adapter.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Structural/Adapter/Adapter.dia -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Adapter/Adapter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Structural/Adapter/Adapter.png -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Adapter/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | hdmiToVgaAdapter = require './API/connections' 4 | 5 | # ============================== 6 | # CLIENT CODE 7 | # ============================== 8 | 9 | console.log hdmiToVgaAdapter.handleDigitalSignal() # Your computer uses HDMI and your projector uses VGA 10 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Adapter/ECMAScript/ES5/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var hdmiToVgaAdapter = require('./API/connections'); 4 | 5 | // ============================== 6 | // CLIENT CODE 7 | // ============================== 8 | 9 | console.log(hdmiToVgaAdapter.handleDigitalSignal()); // Your computer uses HDMI and your projector uses VGA 10 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Adapter/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import hdmiToVgaAdapter from './API/connections'; 2 | 3 | // ============================== 4 | // TEST 5 | // ============================== 6 | 7 | console.log(hdmiToVgaAdapter.handleDigitalSignal()); // Your computer uses HDMI and your projector uses VGA 8 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Adapter/TypeScript/client.ts: -------------------------------------------------------------------------------- 1 | import { hdmiToVgaAdapter } from './API/connections'; 2 | 3 | // ============================== 4 | // CLIENT CODE 5 | // ============================== 6 | 7 | console.log(hdmiToVgaAdapter.handleDigitalSignal()); // Your computer uses HDMI and your projector uses VGA 8 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Bridge/Bridge.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Structural/Bridge/Bridge.dia -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Bridge/Bridge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Structural/Bridge/Bridge.png -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Bridge/CoffeeScript/API/recipes.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # RECIPES 5 | # ============================== 6 | 7 | pasta = (sauce) -> 8 | cook: -> 9 | "Pasta with #{sauce.ingredients()}" 10 | 11 | risotto = (sauce) -> 12 | cook: -> 13 | "Risotto with #{sauce.ingredients()}" 14 | 15 | module.exports = 16 | pasta: pasta 17 | risotto: risotto 18 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Bridge/CoffeeScript/API/sauces.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # SAUCES 5 | # ============================== 6 | 7 | pesto = 8 | ingredients: -> 9 | "Pesto (basil, garlic, oil, grated cheese, pine nuts)" 10 | 11 | carbonara = 12 | ingredients: -> 13 | "Carbonara (eggs, bacon, black pepper, grated cheese)" 14 | 15 | module.exports = 16 | pesto: pesto 17 | carbonara: carbonara 18 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Bridge/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | sauces = require './API/sauces' 4 | recipes = require './API/recipes' 5 | 6 | # ============================== 7 | # CLIENT CODE 8 | # ============================== 9 | 10 | console.log recipes.pasta(sauces.pesto).cook() 11 | console.log recipes.risotto(sauces.carbonara).cook() 12 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Bridge/ECMAScript/ES5/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var sauces = require('./API/sauces'), 4 | recipes = require('./API/recipes'); 5 | 6 | // ============================== 7 | // CLIENT CODE 8 | // ============================== 9 | 10 | console.log(recipes.pasta(sauces.pesto).cook()); 11 | console.log(recipes.risotto(sauces.carbonara).cook()); 12 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Bridge/ECMAScript/ES6/API/sauces.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // SAUCES 3 | // ============================== 4 | 5 | export const pesto = { 6 | ingredients() { 7 | return "Pesto (basil, garlic, oil, grated cheese, pine nuts)"; 8 | } 9 | }; 10 | 11 | export const carbonara = { 12 | ingredients() { 13 | return "Carbonara (eggs, bacon, black pepper, grated cheese)"; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Bridge/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import { pesto, carbonara } from './API/sauces'; 2 | import { pasta, risotto } from './API/recipes'; 3 | 4 | // ============================== 5 | // CLIENT CODE 6 | // ============================== 7 | 8 | console.log(pasta(pesto).cook()); 9 | console.log(risotto(carbonara).cook()); 10 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Bridge/TypeScript/client.ts: -------------------------------------------------------------------------------- 1 | import { pesto, carbonara } from './API/sauces'; 2 | import { pasta, risotto } from './API/recipes'; 3 | 4 | // ============================== 5 | // TEST 6 | // ============================== 7 | 8 | console.log(pasta(pesto).cook()); 9 | console.log(risotto(carbonara).cook()); 10 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Composite/Composite.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Structural/Composite/Composite.dia -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Composite/Composite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Structural/Composite/Composite.png -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Decorator/CoffeeScript/Decorator.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | pizza = require './API/pizza' 4 | 5 | # ============================== 6 | # CLIENT CODE 7 | # ============================== 8 | 9 | console.log pizza.peppers(pizza.bacon(pizza.margherita)).ingredients() 10 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Decorator/Decorator.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Structural/Decorator/Decorator.dia -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Decorator/Decorator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Structural/Decorator/Decorator.png -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Decorator/ECMAScript/ES5/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var pizza = require('./API/pizza'); 4 | 5 | // ============================== 6 | // CLIENT CODE 7 | // ============================== 8 | 9 | console.log(pizza.peppers(pizza.bacon(pizza.margherita)).ingredients()); 10 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Decorator/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import { margherita, addBacon, addPeppers } from './API/pizza'; 2 | 3 | // ============================== 4 | // CLIENT CODE 5 | // ============================== 6 | 7 | console.log(addPeppers(addBacon(margherita)).ingredients()); 8 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Decorator/TypeScript/client.ts: -------------------------------------------------------------------------------- 1 | import { margherita, addBacon, addPeppers } from './API/pizza'; 2 | 3 | // ============================== 4 | // CLIENT CODE 5 | // ============================== 6 | 7 | console.log(addPeppers(addBacon(margherita)).ingredients()); 8 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Facade/CoffeeScript/API/animals.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | # ============================== 4 | # ANIMALS 5 | # ============================== 6 | 7 | dog = 8 | eat: -> 9 | "Dog: 'Meat, please!'\n" 10 | 11 | rabbit = 12 | eat: -> 13 | "Rabbit: 'A carrot would be great!'\n" 14 | 15 | module.exports = 16 | dog: dog 17 | rabbit: rabbit 18 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Facade/CoffeeScript/API/facade.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | animals = require './animals' 4 | 5 | # ============================== 6 | # THE FACADE 7 | # ============================== 8 | 9 | module.exports = 10 | dog: animals.dog 11 | rabbit: animals.rabbit 12 | feedAnimals: -> 13 | "#{@dog.eat()}#{@rabbit.eat()}" 14 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Facade/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | facade = require './API/facade' 4 | 5 | # ============================== 6 | # CLIENT CODE 7 | # ============================== 8 | 9 | console.log facade.feedAnimals() 10 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Facade/ECMAScript/ES5/API/animals.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // ============================== 4 | // ANIMALS 5 | // ============================== 6 | 7 | var dog = { 8 | eat: function () { 9 | return "Dog: 'Meat, please!'\n"; 10 | } 11 | }; 12 | 13 | var rabbit = { 14 | eat: function () { 15 | return "Rabbit: 'A carrot would be great!'\n"; 16 | } 17 | }; 18 | 19 | module.exports = { 20 | dog: dog, 21 | rabbit: rabbit 22 | }; 23 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Facade/ECMAScript/ES5/API/facade.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var animals = require('./animals'); 4 | 5 | // ============================== 6 | // THE FACADE 7 | // ============================== 8 | 9 | module.exports = { 10 | dog: animals.dog, 11 | rabbit: animals.rabbit, 12 | feedAnimals: function () { 13 | return this.dog.eat() + this.rabbit.eat(); 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Facade/ECMAScript/ES5/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var facade = require('./API/facade'); 4 | 5 | // ============================== 6 | // CLIENT CODE 7 | // ============================== 8 | 9 | console.log(facade.feedAnimals()); 10 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Facade/ECMAScript/ES6/API/animals.js: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ANIMALS 3 | // ============================== 4 | 5 | export const dog = { 6 | eat() { 7 | return "Dog: 'Meat, please!'\n"; 8 | } 9 | }; 10 | 11 | export const rabbit = { 12 | eat() { 13 | return "Rabbit: 'A carrot would be great!'\n"; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Facade/ECMAScript/ES6/API/facade.js: -------------------------------------------------------------------------------- 1 | import { dog, rabbit } from './animals'; 2 | 3 | // ============================== 4 | // THE FACADE 5 | // ============================== 6 | 7 | export default { 8 | dog, 9 | rabbit, 10 | feedAnimals() { 11 | return `${this.dog.eat()}${this.rabbit.eat()}`; 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Facade/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import facade from './API/facade'; 2 | 3 | // ============================== 4 | // CLIENT CODE 5 | // ============================== 6 | 7 | console.log(facade.feedAnimals()); 8 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Facade/Facade.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Structural/Facade/Facade.dia -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Facade/Facade.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Structural/Facade/Facade.png -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Facade/TypeScript/API/animals.ts: -------------------------------------------------------------------------------- 1 | // ============================== 2 | // ANIMALS 3 | // ============================== 4 | 5 | export interface Animal { 6 | eat(): string; 7 | } 8 | 9 | export const dog: Animal = { 10 | eat() { 11 | return "Dog: 'Meat, please!'\n"; 12 | } 13 | }; 14 | 15 | export const rabbit: Animal = { 16 | eat() { 17 | return "Rabbit: 'A carrot would be great!'\n"; 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Facade/TypeScript/client.ts: -------------------------------------------------------------------------------- 1 | import { facade } from './API/facade'; 2 | 3 | // ============================== 4 | // CLIENT CODE 5 | // ============================== 6 | 7 | console.log(facade.feedAnimals()); 8 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Flyweight/Flyweight.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Structural/Flyweight/Flyweight.dia -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Flyweight/Flyweight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Structural/Flyweight/Flyweight.png -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Proxy/CoffeeScript/client.coffee: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | atm = require './API/finance' 4 | 5 | # ============================== 6 | # CLIENT CODE 7 | # ============================== 8 | 9 | try 10 | console.log atm.withdrawMoney 1234 # Wrong code 11 | catch e 12 | console.log "#{e.type} - #{e.message}" # AuthenticationException - Invalid code 13 | finally 14 | console.log atm.withdrawMoney 1337 # Enjoy the cash! 15 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Proxy/ECMAScript/ES5/client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var atm = require('./API/finance'); 4 | 5 | // ============================== 6 | // CLIENT CODE 7 | // ============================== 8 | 9 | try { 10 | console.log(atm.withdrawMoney(1234)); // Wrong code 11 | } catch (e) { 12 | console.log(e.type + " - " + e.message); // AuthenticationException - Invalid code 13 | } finally { 14 | console.log(atm.withdrawMoney(1337)); // Enjoy the cash! 15 | } 16 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Proxy/ECMAScript/ES6/client.js: -------------------------------------------------------------------------------- 1 | import atm from './API/finance'; 2 | 3 | // ============================== 4 | // CLIENT CODE 5 | // ============================== 6 | 7 | try { 8 | console.log(atm.withdrawMoney(1234)); // Wrong code 9 | } catch (e) { 10 | console.log(e.type + " - " + e.message); // AuthenticationException - Invalid code 11 | } finally { 12 | console.log(atm.withdrawMoney(1337)); // Enjoy the cash! 13 | } 14 | -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Proxy/Proxy.dia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Structural/Proxy/Proxy.dia -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Proxy/Proxy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Badacadabra/JavaScript-Design-Patterns/c6d6dd1b0a045ef485de207206b82e33f81c511d/GoF/idiomatic/Structural/Proxy/Proxy.png -------------------------------------------------------------------------------- /GoF/idiomatic/Structural/Proxy/TypeScript/client.ts: -------------------------------------------------------------------------------- 1 | import atm from './API/finance'; 2 | 3 | // ============================== 4 | // CLIENT CODE 5 | // ============================== 6 | 7 | try { 8 | console.log(atm.withdrawMoney(1234)); // Wrong code 9 | } catch (e) { 10 | console.log(e.type + " - " + e.message); // AuthenticationException - Invalid code 11 | } finally { 12 | console.log(atm.withdrawMoney(1337)); // Enjoy the cash! 13 | } 14 | -------------------------------------------------------------------------------- /misc/Currying/ECMAScript/ES6/index.js: -------------------------------------------------------------------------------- 1 | const profile = firstName => { 2 | return lastName => { 3 | return age => { 4 | return gender => { 5 | return nationality => `First name: ${firstName} 6 | Last name: ${lastName} 7 | Age: ${age} 8 | Gender: ${gender} 9 | Nationality: ${nationality}` 10 | }; 11 | }; 12 | }; 13 | }; 14 | 15 | let myProfile = profile("Baptiste")("Vannesson")(27)("M")("French"); 16 | 17 | console.log(myProfile); 18 | -------------------------------------------------------------------------------- /misc/MethodChaining/README.md: -------------------------------------------------------------------------------- 1 | # Problem 2 | 3 | In a program, we may have a lot of function calls on the same object. This often leads to repetition because it is necessary to write the reference again and again. 4 | 5 | # Solution 6 | 7 | Method Chaining allows us to make multiple calls on the same object without repeating ourselves. This pattern is very easy to use because the only thing to do is to return the current object ("this") in all methods that are supposed to be "chainable". 8 | -------------------------------------------------------------------------------- /misc/ObjectSpecifier/CoffeeScript/index.coffee: -------------------------------------------------------------------------------- 1 | profile = (person) -> 2 | """ 3 | First name: #{person.firstName} 4 | Last name: #{person.lastName} 5 | Age: #{person.age} 6 | Gender: #{person.gender} 7 | Nationality: #{person.nationality} 8 | """ 9 | 10 | myProfile = profile 11 | nationality: "French" 12 | gender: "M" 13 | firstName: "Baptiste" 14 | lastName: "Vannesson" 15 | age: 27 16 | 17 | console.log myProfile 18 | -------------------------------------------------------------------------------- /misc/ObjectSpecifier/ECMAScript/ES6/index.js: -------------------------------------------------------------------------------- 1 | const profile = ({ firstName, lastName, age, gender, nationality }) => `First name: ${firstName} 2 | Last name: ${lastName} 3 | Age: ${age} 4 | Gender: ${gender} 5 | Nationality: ${nationality}` 6 | 7 | let myProfile = profile({ 8 | nationality: "French", 9 | gender: "M", 10 | firstName: "Baptiste", 11 | lastName: "Vannesson", 12 | age: 27 13 | }); 14 | 15 | console.log(myProfile); 16 | --------------------------------------------------------------------------------