├── workshop-javascript
├── solutions
│ ├── Problem1
│ │ ├── quadratic-equations.html
│ │ └── index.html
│ ├── Problem4
│ │ ├── balon.gif
│ │ ├── field.png
│ │ ├── index.html
│ │ └── style.css
│ ├── Problem3
│ │ ├── css
│ │ │ ├── img
│ │ │ │ ├── rope.png
│ │ │ │ └── campo.jpeg
│ │ │ └── rope.css
│ │ └── rope.html
│ └── Problem2
│ │ ├── index.html
│ │ └── main.js
└── problems
│ ├── Problem4
│ ├── balon.gif
│ ├── field.png
│ ├── index.html
│ └── style.css
│ ├── Problem3
│ ├── css
│ │ ├── img
│ │ │ ├── campo.jpeg
│ │ │ └── rope.png
│ │ └── rope.css
│ └── rope.html
│ ├── Problem2
│ ├── main.js
│ └── index.html
│ └── Problem1
│ └── index.html
├── composite-pattern
├── example1
│ ├── component.ts
│ ├── leaf.ts
│ ├── index.ts
│ ├── composite.ts
│ └── uml.puml
├── example2
│ ├── solution
│ │ ├── recipe-component.ts
│ │ ├── ingredient.ts
│ │ ├── index.ts
│ │ └── recipe.ts
│ └── problem
│ │ ├── ingredient.ts
│ │ └── index.ts
├── nodemon-example1.json
├── nodemon-example2-problem.json
├── nodemon-example2-solve.json
└── package.json
├── prototype-pattern
├── example2
│ ├── solution
│ │ ├── clonable.ts
│ │ └── index.ts
│ └── problem
│ │ ├── index.ts
│ │ └── uml.puml
├── example1
│ ├── prototype.ts
│ ├── concrete-prototype2.ts
│ ├── concrete.prototype1.ts
│ ├── index.ts
│ └── uml.puml
├── nodemon-example1.json
├── nodemon-example2-problem.json
├── nodemon-example2-solve.json
└── package.json
├── factory-method-pattern
├── example3
│ ├── product.interface.ts
│ ├── kebab.model.ts
│ ├── pizza.model.ts
│ ├── burger.model.ts
│ ├── kebab-creator.ts
│ ├── pizza-creator.ts
│ ├── burger-creator.ts
│ ├── creator.ts
│ └── index.ts
├── example1
│ ├── product.interface.ts
│ ├── concrete-product1.ts
│ ├── concrete-product2.ts
│ ├── creator.ts
│ ├── concrete-creator1.ts
│ ├── concrete-creator2.ts
│ └── index.ts
├── example2
│ ├── product.interface.ts
│ ├── product-type.enum.ts
│ ├── burger.model.ts
│ ├── kebab.model.ts
│ ├── pizza.model.ts
│ ├── index.ts
│ └── product-manager.ts
├── nodemon-example1.json
├── nodemon-example2.json
├── nodemon-example3.json
├── nodemon-example4.json
├── README.md
└── package.json
├── adapter-pattern
├── example2
│ ├── interfaces
│ │ └── pure-race.interface.ts
│ └── models
│ │ ├── human.model.ts
│ │ ├── namekian.ts
│ │ ├── saiyan.model.ts
│ │ ├── human-adapter.model.ts
│ │ ├── namekian-adapter.model.ts
│ │ └── saiyan-adapter.model.ts
├── example1
│ ├── interfaces
│ │ └── warrior.interface.ts
│ ├── models
│ │ ├── android.model.ts
│ │ ├── namekian.ts
│ │ ├── saiyan.model.ts
│ │ └── android-adapter.model.ts
│ └── index.ts
├── nodemon-example1.json
├── nodemon-example2.json
├── README.md
└── package.json
├── decorator-pattern
├── example1
│ ├── problem
│ │ ├── component.interface.ts
│ │ ├── component-base.ts
│ │ ├── component-a.ts
│ │ ├── component-b.ts
│ │ ├── component-ba.ts
│ │ ├── component-c.ts
│ │ ├── component-ca.ts
│ │ └── component-cba.ts
│ └── decorator-solution-1
│ │ ├── component.interface.ts
│ │ ├── concrete-component.ts
│ │ ├── concrete-decorator-a.ts
│ │ ├── concrete-decorator-b.ts
│ │ ├── concrete-decorator-c.ts
│ │ └── decorator.ts
├── render1560346139406.gif
├── tsconfig.json
├── nodemon-example1-problem.json
├── nodemon-example1-decorator-solution-1.json
├── nodemon-example2-decorator-solution-1.json
├── README.md
├── example2
│ └── decorator-solution
│ │ ├── character.interface.ts
│ │ ├── lord-decorator.ts
│ │ └── white-walker-decorator.ts
└── package.json
├── abstract-factory-pattern
├── example1
│ ├── abstract-productA.ts
│ ├── abstract-productB.ts
│ ├── concrete-productA1.ts
│ ├── concrete-productA2.ts
│ ├── concrete-productB1.ts
│ ├── concrete-productB2.ts
│ ├── abstract-factory.ts
│ ├── concrete-factory1.ts
│ ├── concrete-factory2.ts
│ └── index.ts
├── example2
│ ├── weapons
│ │ ├── weapon.interface.ts
│ │ ├── axe.model.ts
│ │ ├── sword.model.ts
│ │ └── mage-fireball.model.ts
│ ├── armor
│ │ ├── armor-interface.ts
│ │ ├── cloak.model.ts
│ │ ├── orc-armor.model.ts
│ │ └── body-armor.model.ts
│ ├── abstract-factory.ts
│ ├── orc-factory.ts
│ ├── warrior-factory.ts
│ ├── mage-factory.ts
│ └── index.ts
├── nodemon-example1.json
├── nodemon-example2.json
├── README.md
└── package.json
├── iterator-pattern
├── render1560345403864.gif
├── render1560346139406.gif
├── tsconfig.json
├── nodemon-example1-problem.json
├── README.md
├── nodemon-example2-iterator-solution-1.json
├── nodemon-example1-iterator-solution-1.json
├── example2
│ └── iterator-solution
│ │ ├── profile-iterator.interface.ts
│ │ └── social-network.interface.ts
└── example1
│ ├── iterator-solution-1
│ ├── agregator.interface.ts
│ ├── iterator.interface.ts
│ ├── index.ts
│ └── words-collection.ts
│ └── problem
│ ├── words-collection.ts
│ ├── example1.puml
│ ├── index.ts
│ └── uml.puml
├── chain-responsibility-pattern
├── tsconfig.json
├── example2
│ ├── interfaces
│ │ ├── index.ts
│ │ ├── user.interface.ts
│ │ └── handler.ts
│ ├── middlewares
│ │ ├── index.ts
│ │ ├── role.middleware.ts
│ │ ├── middleware.ts
│ │ └── user-exists.middleware.ts
│ └── app.constants.ts
├── example1
│ ├── handler.ts
│ ├── handlerA.ts
│ ├── handlerB.ts
│ ├── handlerC.ts
│ └── abstract-handler.ts
├── nodemon-example1.json
├── nodemon-example2.json
├── README.md
└── package.json
├── command-pattern
├── example2
│ └── command-solution-1
│ │ ├── services
│ │ ├── index.ts
│ │ ├── store.service.ts
│ │ └── r2d2.service.ts
│ │ ├── commands
│ │ ├── index.ts
│ │ ├── command.class.ts
│ │ ├── clean-command.ts
│ │ ├── move-command.ts
│ │ └── save-secret-command.ts
│ │ ├── r2d2.ts
│ │ └── index.ts
├── example1
│ ├── problem
│ │ ├── index.ts
│ │ ├── stock.trader.class.ts
│ │ └── agent.class.ts
│ └── command-solution-1
│ │ ├── stock.trader.class.ts
│ │ ├── order.class.ts
│ │ ├── agent.class.ts
│ │ ├── sell-stock-order.ts
│ │ ├── buy-stock-order.ts
│ │ └── index.ts
├── nodemon-example1-problem.json
├── README.md
├── nodemon-example1-command-solution-1.json
├── nodemon-example2-command-solution-1.json
└── package.json
├── facade-pattern
├── example1
│ ├── problem
│ │ ├── system2
│ │ │ ├── classC2.ts
│ │ │ ├── classC.ts
│ │ │ ├── classD.ts
│ │ │ └── classC3.ts
│ │ ├── system1
│ │ │ ├── classA.ts
│ │ │ ├── classB.ts
│ │ │ └── classA2.ts
│ │ └── index.ts
│ ├── facade-solution-1
│ │ ├── system2
│ │ │ ├── classC2.ts
│ │ │ ├── classC3.ts
│ │ │ ├── classC.ts
│ │ │ └── classD.ts
│ │ ├── system1
│ │ │ ├── classA.ts
│ │ │ ├── classB.ts
│ │ │ └── classA2.ts
│ │ └── index.ts
│ └── facade-solution-2
│ │ ├── system2
│ │ ├── classC2.ts
│ │ ├── classC.ts
│ │ ├── classD.ts
│ │ ├── classC3.ts
│ │ └── facade-system2.ts
│ │ ├── system1
│ │ ├── classA.ts
│ │ ├── classB.ts
│ │ ├── classA2.ts
│ │ └── facade-system1.ts
│ │ ├── index.ts
│ │ └── facade.ts
├── example2
│ ├── problem
│ │ ├── dragonball
│ │ │ ├── interfaces
│ │ │ │ └── pure-race.interface.ts
│ │ │ └── models
│ │ │ │ ├── human.model.ts
│ │ │ │ ├── namekian.ts
│ │ │ │ ├── saiyan.model.ts
│ │ │ │ ├── human-adapter.model.ts
│ │ │ │ ├── namekian-adapter.model.ts
│ │ │ │ └── saiyan-adapter.model.ts
│ │ └── pokemon
│ │ │ ├── fighting-pokemon.model.ts
│ │ │ ├── ground-pokemon.model.ts
│ │ │ └── poison-pokemon.model.ts
│ └── facade-solution
│ │ ├── dragonball
│ │ ├── interfaces
│ │ │ └── pure-race.interface.ts
│ │ └── models
│ │ │ ├── human.model.ts
│ │ │ ├── namekian.model.ts
│ │ │ ├── saiyan.model.ts
│ │ │ ├── human-adapter.model.ts
│ │ │ ├── namekian-adapter.model.ts
│ │ │ └── saiyan-adapter.model.ts
│ │ ├── pokemon
│ │ ├── ground-pokemon.model.ts
│ │ ├── poison-pokemon.model.ts
│ │ ├── fighting-pokemon.model.ts
│ │ └── pokemon-facade.ts
│ │ └── index.ts
├── nodemon-example1-problem.json
├── nodemon-example2-problem.json
├── README.md
├── nodemon-example2-facade-solution-1.json
├── nodemon-example1-facade-solution-1.json
├── nodemon-example1-facade-solution-2.json
└── package.json
├── null-object-pattern
├── example1
│ ├── problem
│ │ ├── saiyan.interface.ts
│ │ ├── saiyan.class.ts
│ │ └── saiyan-factory.class.ts
│ └── null-object-solution-1
│ │ ├── saiyan.interface.ts
│ │ ├── saiyan.class.ts
│ │ ├── null-saiyan.class.ts
│ │ ├── real-saiyan.class.ts
│ │ ├── index.ts
│ │ └── saiyan-factory.class.ts
├── nodemon-example1-problem.json
├── nodemon-example1-solution-1.json
├── README.md
└── package.json
├── observer-pattern
├── tsconfig.json
├── example1
│ ├── observer.interface.ts
│ ├── subject.interface.ts
│ ├── concrete-observerA.ts
│ ├── concrete-observerB.ts
│ └── index.ts
├── nodemon-example1.json
├── nodemon-example2.json
├── README.md
├── example2
│ ├── auctioneer.interface.ts
│ ├── agent.interface.ts
│ └── product.model.ts
└── package.json
├── singleton-pattern
├── example2
│ ├── singleton-solution
│ │ ├── hero.interface.ts
│ │ ├── index.ts
│ │ ├── batman.ts
│ │ ├── spiderman.ts
│ │ ├── client1.ts
│ │ ├── client2.ts
│ │ └── hero-base.class.ts
│ └── problem
│ │ ├── index.ts
│ │ ├── client1.ts
│ │ ├── client2.ts
│ │ └── database-connection.ts
├── nodemon-example1-problem.json
├── nodemon-example2-problem.json
├── nodemon-example1-singleton-solution-1.json
├── nodemon-example2-singleton-solution-1.json
├── README.md
├── example1
│ ├── problem
│ │ ├── index.ts
│ │ ├── client1.ts
│ │ ├── client2.ts
│ │ ├── database-connection.ts
│ │ └── database-problem.plantuml
│ └── singleton-solution-1
│ │ ├── index.ts
│ │ ├── client1.ts
│ │ ├── client2.ts
│ │ └── database-connection.ts
└── package.json
├── strategy-pattern
├── strategy1.html
├── strategy2.html
├── README.md
└── strategy1.js
├── flyweight-pattern
├── example2
│ ├── problem
│ │ ├── interfaces
│ │ │ ├── team.interface.ts
│ │ │ ├── position.interface.ts
│ │ │ ├── index.ts
│ │ │ └── stats.interface.ts
│ │ ├── models
│ │ │ ├── team.ts
│ │ │ ├── position.ts
│ │ │ ├── stats.ts
│ │ │ ├── index.ts
│ │ │ └── player.ts
│ │ └── sports-simulator.ts
│ └── solution
│ │ ├── interfaces
│ │ ├── team.interface.ts
│ │ ├── position.interface.ts
│ │ ├── index.ts
│ │ └── stats.interface.ts
│ │ ├── models
│ │ ├── team.ts
│ │ ├── position.ts
│ │ ├── stats.ts
│ │ └── index.ts
│ │ ├── flyweight.ts
│ │ ├── flyweight.factory.ts
│ │ ├── team-flyweight.ts
│ │ └── position-flyweight.ts
├── example1
│ ├── flyweight.ts
│ ├── concrete-flyweight.ts
│ ├── unshared-flyweight.ts
│ └── index.ts
├── nodemon-example1.json
├── nodemon-example2-problem.json
├── nodemon-example2-solve.json
└── package.json
├── proxy-pattern
├── example2
│ ├── subjects
│ │ ├── subject.interface.ts
│ │ ├── subject-cache.interface.ts
│ │ ├── real-subject.ts
│ │ ├── index.ts
│ │ └── real-subject-cache.ts
│ └── proxies
│ │ ├── index.ts
│ │ ├── lazy.proxy.ts
│ │ ├── logging.proxy.ts
│ │ └── access.proxy.ts
├── nodemon-example1.json
├── nodemon-example2-problem.json
├── nodemon-example2-solve.json
├── package.json
└── example1
│ └── uml.puml
├── state-pattern
├── example1
│ ├── problem
│ │ ├── state.enum.ts
│ │ └── index.ts
│ └── state-solution-1
│ │ ├── index.ts
│ │ ├── state.ts
│ │ ├── concrete-state-A.ts
│ │ ├── concrete-state-B.ts
│ │ └── context.ts
├── tsconfig.json
├── nodemon-example1-problem.json
├── nodemon-example2-problem.json
├── nodemon-example2-state-solution-1.json
├── README.md
├── nodemon-example1-state-solution-1.json
├── example2
│ ├── problem
│ │ ├── state.enum.ts
│ │ └── index.ts
│ └── solution
│ │ ├── index.ts
│ │ ├── state.ts
│ │ └── freeza.ts
└── package.json
├── bridge-pattern
├── example2
│ ├── solution
│ │ ├── message-sender.ts
│ │ ├── advanced-messaging.ts
│ │ ├── messaging-sender.ts
│ │ ├── desktop-sender.ts
│ │ ├── mobile-sender.ts
│ │ └── index.ts
│ └── problem
│ │ ├── desktop-messaging.ts
│ │ ├── mobile-messaging.ts
│ │ └── index.ts
├── nodemon-example1.json
├── nodemon-example2-solve.json
├── nodemon-example2-problem.json
├── example1
│ ├── implementor.ts
│ ├── concrete-implementorB.ts
│ ├── concrete-implementorA.ts
│ ├── refine-abstraction.ts
│ └── abstraction.ts
└── package.json
├── understanding-this-in-js
├── 01-global-browser
│ ├── global-browser.html
│ └── global-browser.js
├── 03-keyword-new
│ ├── new-01.js
│ ├── new-02.js
│ └── new-03.js
├── README.md
├── 09 - exercises
│ └── exercise-01.js
├── 07-fat-arrow
│ ├── fat-arrow.js
│ └── fat-arrow-bad.js
├── 08-class
│ └── class.js
├── 05-call-apply
│ └── call-apply.js
├── 06-bind
│ └── bind.js
├── 02-global-nodejs
│ └── global-nodejs.js
├── 04-invoker-object
│ └── invoker-object.js
└── package.json
├── demeter
├── nodemon-example1.json
├── example1
│ ├── interfaces
│ │ ├── person.interface.ts
│ │ ├── address.interface.ts
│ │ ├── house.interface.ts
│ │ └── fake-object.ts
│ ├── models
│ │ ├── house.model.ts
│ │ └── person.model.ts
│ └── index.ts
└── package.json
├── mediator-pattern
├── example1
│ ├── mediator.ts
│ ├── colleague.ts
│ ├── colleague1.ts
│ ├── colleague2.ts
│ └── index.ts
├── nodemon-example1.json
├── nodemon-example2-problem.json
├── nodemon-example2-solve.json
├── example2
│ └── solution
│ │ ├── sensor.ts
│ │ ├── actuator.ts
│ │ ├── iot-mediator.ts
│ │ └── index.ts
└── package.json
├── iterators-javascript
├── nodemon-example1-problem.json
├── README.md
├── nodemon-example2-iterator-solution-1.json
├── nodemon-example1-iterator-solution-1.json
├── example2
│ └── iterator-solution
│ │ ├── profile-iterator.interface.ts
│ │ └── social-network.interface.ts
└── example1
│ ├── iterator-solution-1
│ ├── agregator.interface.ts
│ └── iterator.interface.ts
│ └── problem
│ ├── words-collection.ts
│ └── index.ts
├── template-method-pattern
├── README.md
└── package.json
├── memoization
└── index.html
├── .gitignore
└── refactoring-caesar
└── package.json
/workshop-javascript/solutions/Problem1/quadratic-equations.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/composite-pattern/example1/component.ts:
--------------------------------------------------------------------------------
1 | export interface Component {
2 | operation(): void;
3 | }
4 |
--------------------------------------------------------------------------------
/prototype-pattern/example2/solution/clonable.ts:
--------------------------------------------------------------------------------
1 | export interface Clonable {
2 | clone(): this;
3 | }
4 |
--------------------------------------------------------------------------------
/factory-method-pattern/example3/product.interface.ts:
--------------------------------------------------------------------------------
1 | export interface Product {
2 | operation(): string;
3 | }
--------------------------------------------------------------------------------
/factory-method-pattern/example1/product.interface.ts:
--------------------------------------------------------------------------------
1 | export interface Product {
2 | operation(): string;
3 | }
4 |
--------------------------------------------------------------------------------
/factory-method-pattern/example2/product.interface.ts:
--------------------------------------------------------------------------------
1 | export interface Product {
2 | operation(): string;
3 | }
4 |
--------------------------------------------------------------------------------
/adapter-pattern/example2/interfaces/pure-race.interface.ts:
--------------------------------------------------------------------------------
1 | export interface PureRace {
2 | genki(): number;
3 | }
4 |
--------------------------------------------------------------------------------
/decorator-pattern/example1/problem/component.interface.ts:
--------------------------------------------------------------------------------
1 | export interface Component {
2 | operation(): string;
3 | }
4 |
--------------------------------------------------------------------------------
/prototype-pattern/example1/prototype.ts:
--------------------------------------------------------------------------------
1 | export interface Prototype {
2 | operation(): void;
3 | clone(): Prototype;
4 | }
--------------------------------------------------------------------------------
/abstract-factory-pattern/example1/abstract-productA.ts:
--------------------------------------------------------------------------------
1 | export interface AbstractProductA {
2 | usefulFunctionA(): string;
3 | }
4 |
--------------------------------------------------------------------------------
/abstract-factory-pattern/example1/abstract-productB.ts:
--------------------------------------------------------------------------------
1 | export interface AbstractProductB {
2 | usefulFunctionB(): string;
3 | }
4 |
--------------------------------------------------------------------------------
/abstract-factory-pattern/example2/weapons/weapon.interface.ts:
--------------------------------------------------------------------------------
1 | export interface Weapon {
2 | usefulFunction(): string;
3 | }
4 |
--------------------------------------------------------------------------------
/composite-pattern/example2/solution/recipe-component.ts:
--------------------------------------------------------------------------------
1 | export interface RecipeComponent {
2 | showDetails(): string;
3 | }
4 |
--------------------------------------------------------------------------------
/decorator-pattern/render1560346139406.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Caballerog/blog/HEAD/decorator-pattern/render1560346139406.gif
--------------------------------------------------------------------------------
/iterator-pattern/render1560345403864.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Caballerog/blog/HEAD/iterator-pattern/render1560345403864.gif
--------------------------------------------------------------------------------
/iterator-pattern/render1560346139406.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Caballerog/blog/HEAD/iterator-pattern/render1560346139406.gif
--------------------------------------------------------------------------------
/chain-responsibility-pattern/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "lib": ["es7"],
4 | "target": "es5"
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/command-pattern/example2/command-solution-1/services/index.ts:
--------------------------------------------------------------------------------
1 | export * from './store.service';
2 | export * from './r2d2.service';
3 |
--------------------------------------------------------------------------------
/decorator-pattern/example1/decorator-solution-1/component.interface.ts:
--------------------------------------------------------------------------------
1 | export interface Component {
2 | operation(): string;
3 | }
4 |
--------------------------------------------------------------------------------
/facade-pattern/example1/problem/system2/classC2.ts:
--------------------------------------------------------------------------------
1 | import { ClassC } from './classC';
2 |
3 | export class ClassC2 extends ClassC {}
4 |
--------------------------------------------------------------------------------
/facade-pattern/example2/problem/dragonball/interfaces/pure-race.interface.ts:
--------------------------------------------------------------------------------
1 | export interface PureRace {
2 | genki(): number;
3 | }
4 |
--------------------------------------------------------------------------------
/null-object-pattern/example1/problem/saiyan.interface.ts:
--------------------------------------------------------------------------------
1 | export interface ISaiyan {
2 | name: string;
3 | power: number;
4 | }
5 |
--------------------------------------------------------------------------------
/observer-pattern/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "lib": ["dom", "es7"],
4 |
5 | "target": "es5"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/singleton-pattern/example2/singleton-solution/hero.interface.ts:
--------------------------------------------------------------------------------
1 | export interface Hero {
2 | name: string;
3 | city: string;
4 | }
5 |
--------------------------------------------------------------------------------
/strategy-pattern/strategy1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/strategy-pattern/strategy2.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/adapter-pattern/example2/models/human.model.ts:
--------------------------------------------------------------------------------
1 | export class Human {
2 | public sharedPower(): number {
3 | return 10;
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/chain-responsibility-pattern/example2/interfaces/index.ts:
--------------------------------------------------------------------------------
1 | export { Handler } from "./handler";
2 | export { User } from "./user.interface";
3 |
--------------------------------------------------------------------------------
/flyweight-pattern/example2/problem/interfaces/team.interface.ts:
--------------------------------------------------------------------------------
1 | export interface ITeam {
2 | name: string;
3 | coach: string;
4 | };
--------------------------------------------------------------------------------
/flyweight-pattern/example2/solution/interfaces/team.interface.ts:
--------------------------------------------------------------------------------
1 | export interface ITeam {
2 | name: string;
3 | coach: string;
4 | };
--------------------------------------------------------------------------------
/flyweight-pattern/example2/solution/models/team.ts:
--------------------------------------------------------------------------------
1 | export class Team {
2 | constructor(public name: string, public coach: string) {}
3 | }
--------------------------------------------------------------------------------
/proxy-pattern/example2/subjects/subject.interface.ts:
--------------------------------------------------------------------------------
1 | // Common Interface
2 | export interface Subject {
3 | operation(): void;
4 | }
5 |
--------------------------------------------------------------------------------
/state-pattern/example1/problem/state.enum.ts:
--------------------------------------------------------------------------------
1 | export enum State {
2 | stateA = "concrete-state-A",
3 | stateB = "concrete-state-B",
4 | }
--------------------------------------------------------------------------------
/adapter-pattern/example1/interfaces/warrior.interface.ts:
--------------------------------------------------------------------------------
1 | export interface Warrior {
2 | ATTACK_BASE: number;
3 | attack(): number;
4 | }
5 |
--------------------------------------------------------------------------------
/chain-responsibility-pattern/example2/interfaces/user.interface.ts:
--------------------------------------------------------------------------------
1 | export interface User {
2 | email: string;
3 | password: string;
4 | }
5 |
--------------------------------------------------------------------------------
/facade-pattern/example1/facade-solution-1/system2/classC2.ts:
--------------------------------------------------------------------------------
1 | import { ClassC } from './classC';
2 |
3 | export class ClassC2 extends ClassC {}
4 |
--------------------------------------------------------------------------------
/facade-pattern/example1/facade-solution-1/system2/classC3.ts:
--------------------------------------------------------------------------------
1 | import { ClassC } from './classC';
2 |
3 | export class ClassC3 extends ClassC {}
4 |
--------------------------------------------------------------------------------
/facade-pattern/example1/facade-solution-2/system2/classC2.ts:
--------------------------------------------------------------------------------
1 | import { ClassC } from './classC';
2 |
3 | export class ClassC2 extends ClassC {}
4 |
--------------------------------------------------------------------------------
/facade-pattern/example2/facade-solution/dragonball/interfaces/pure-race.interface.ts:
--------------------------------------------------------------------------------
1 | export interface PureRace {
2 | genki(): number;
3 | }
4 |
--------------------------------------------------------------------------------
/flyweight-pattern/example1/flyweight.ts:
--------------------------------------------------------------------------------
1 | // Flyweight Interface
2 | export interface Flyweight {
3 | operation(extrinsicState: any): void;
4 | }
--------------------------------------------------------------------------------
/flyweight-pattern/example2/problem/interfaces/position.interface.ts:
--------------------------------------------------------------------------------
1 | export interface IPosition {
2 | name: string;
3 | role: string;
4 | };
--------------------------------------------------------------------------------
/flyweight-pattern/example2/problem/models/team.ts:
--------------------------------------------------------------------------------
1 | export class Team {
2 | constructor(public name: string, public coach: string) {}
3 | }
4 |
--------------------------------------------------------------------------------
/flyweight-pattern/example2/solution/interfaces/position.interface.ts:
--------------------------------------------------------------------------------
1 | export interface IPosition {
2 | name: string;
3 | role: string;
4 | };
--------------------------------------------------------------------------------
/flyweight-pattern/example2/solution/models/position.ts:
--------------------------------------------------------------------------------
1 | export class Position {
2 | constructor(public name: string, public role: string) {}
3 | }
--------------------------------------------------------------------------------
/null-object-pattern/example1/null-object-solution-1/saiyan.interface.ts:
--------------------------------------------------------------------------------
1 | export interface Saiyan {
2 | name: string;
3 | power: number;
4 | }
5 |
--------------------------------------------------------------------------------
/workshop-javascript/problems/Problem4/balon.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Caballerog/blog/HEAD/workshop-javascript/problems/Problem4/balon.gif
--------------------------------------------------------------------------------
/workshop-javascript/problems/Problem4/field.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Caballerog/blog/HEAD/workshop-javascript/problems/Problem4/field.png
--------------------------------------------------------------------------------
/workshop-javascript/solutions/Problem4/balon.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Caballerog/blog/HEAD/workshop-javascript/solutions/Problem4/balon.gif
--------------------------------------------------------------------------------
/workshop-javascript/solutions/Problem4/field.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Caballerog/blog/HEAD/workshop-javascript/solutions/Problem4/field.png
--------------------------------------------------------------------------------
/facade-pattern/example1/problem/system1/classA.ts:
--------------------------------------------------------------------------------
1 | export class ClassA {
2 | methodA() {
3 | console.log('methodA from Class A');
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/facade-pattern/example1/problem/system1/classB.ts:
--------------------------------------------------------------------------------
1 | export class ClassB {
2 | methodB() {
3 | console.log('methodB from ClassB');
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/facade-pattern/example1/problem/system2/classC.ts:
--------------------------------------------------------------------------------
1 | export class ClassC {
2 | methodC() {
3 | console.log('methodC from ClassC');
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/facade-pattern/example1/problem/system2/classD.ts:
--------------------------------------------------------------------------------
1 | export class ClassD {
2 | methodD() {
3 | console.log('methodD from ClassD');
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/flyweight-pattern/example2/problem/models/position.ts:
--------------------------------------------------------------------------------
1 | export class Position {
2 | constructor(public name: string, public role: string) {}
3 | }
4 |
--------------------------------------------------------------------------------
/adapter-pattern/example2/models/namekian.ts:
--------------------------------------------------------------------------------
1 | export class Namekian {
2 | public getPower(): number {
3 | return Math.random() * 20 + 20;
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/facade-pattern/example1/facade-solution-1/system1/classA.ts:
--------------------------------------------------------------------------------
1 | export class ClassA {
2 | methodA() {
3 | console.log('methodA from Class A');
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/facade-pattern/example1/facade-solution-1/system1/classB.ts:
--------------------------------------------------------------------------------
1 | export class ClassB {
2 | methodB() {
3 | console.log('methodB from ClassB');
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/facade-pattern/example1/facade-solution-1/system2/classC.ts:
--------------------------------------------------------------------------------
1 | export class ClassC {
2 | methodC() {
3 | console.log('methodC from ClassC');
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/facade-pattern/example1/facade-solution-1/system2/classD.ts:
--------------------------------------------------------------------------------
1 | export class ClassD {
2 | methodD() {
3 | console.log('methodD from ClassD');
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/facade-pattern/example1/facade-solution-2/system1/classA.ts:
--------------------------------------------------------------------------------
1 | export class ClassA {
2 | methodA() {
3 | console.log('methodA from Class A');
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/facade-pattern/example1/facade-solution-2/system1/classB.ts:
--------------------------------------------------------------------------------
1 | export class ClassB {
2 | methodB() {
3 | console.log('methodB from ClassB');
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/facade-pattern/example1/facade-solution-2/system2/classC.ts:
--------------------------------------------------------------------------------
1 | export class ClassC {
2 | methodC() {
3 | console.log('methodC from ClassC');
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/facade-pattern/example1/facade-solution-2/system2/classD.ts:
--------------------------------------------------------------------------------
1 | export class ClassD {
2 | methodD() {
3 | console.log('methodD from ClassD');
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/facade-pattern/example2/problem/dragonball/models/human.model.ts:
--------------------------------------------------------------------------------
1 | export class Human {
2 | public sharedPower(): number {
3 | return 10;
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/factory-method-pattern/example2/product-type.enum.ts:
--------------------------------------------------------------------------------
1 | export enum PRODUCT_TYPE {
2 | PIZZA = "Pizza",
3 | KEBAB = "Kebab",
4 | BURGER = "Burger",
5 | }
6 |
--------------------------------------------------------------------------------
/flyweight-pattern/example2/solution/flyweight.ts:
--------------------------------------------------------------------------------
1 | // Flyweight Interfaces
2 | export interface Flyweight {
3 | display(extrinsicState: any): void;
4 | }
5 |
--------------------------------------------------------------------------------
/workshop-javascript/problems/Problem3/css/img/campo.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Caballerog/blog/HEAD/workshop-javascript/problems/Problem3/css/img/campo.jpeg
--------------------------------------------------------------------------------
/workshop-javascript/problems/Problem3/css/img/rope.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Caballerog/blog/HEAD/workshop-javascript/problems/Problem3/css/img/rope.png
--------------------------------------------------------------------------------
/workshop-javascript/solutions/Problem3/css/img/rope.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Caballerog/blog/HEAD/workshop-javascript/solutions/Problem3/css/img/rope.png
--------------------------------------------------------------------------------
/bridge-pattern/example2/solution/message-sender.ts:
--------------------------------------------------------------------------------
1 | export interface MessageSender {
2 | sendMessage(message: string): void;
3 | receiveMessage(): string;
4 | }
--------------------------------------------------------------------------------
/facade-pattern/example2/facade-solution/dragonball/models/human.model.ts:
--------------------------------------------------------------------------------
1 | export class Human {
2 | public sharedPower(): number {
3 | return 10;
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/flyweight-pattern/example2/problem/interfaces/index.ts:
--------------------------------------------------------------------------------
1 | export * from './position.interface';
2 | export * from './stats.interface';
3 | export * from './team.interface';
--------------------------------------------------------------------------------
/flyweight-pattern/example2/problem/interfaces/stats.interface.ts:
--------------------------------------------------------------------------------
1 | export interface IStats {
2 | goals: number;
3 | assists: number;
4 | passes: number;
5 | };
--------------------------------------------------------------------------------
/understanding-this-in-js/01-global-browser/global-browser.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/workshop-javascript/solutions/Problem3/css/img/campo.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Caballerog/blog/HEAD/workshop-javascript/solutions/Problem3/css/img/campo.jpeg
--------------------------------------------------------------------------------
/chain-responsibility-pattern/example1/handler.ts:
--------------------------------------------------------------------------------
1 | export interface Handler {
2 | setNext(handler: Handler): Handler;
3 |
4 | handle(request: string): string;
5 | }
6 |
--------------------------------------------------------------------------------
/flyweight-pattern/example2/problem/models/stats.ts:
--------------------------------------------------------------------------------
1 | export class Stats {
2 | constructor(public goals: number, public assists: number, public matches: number) {}
3 | }
--------------------------------------------------------------------------------
/flyweight-pattern/example2/solution/interfaces/index.ts:
--------------------------------------------------------------------------------
1 | export * from './position.interface';
2 | export * from './stats.interface';
3 | export * from './team.interface';
--------------------------------------------------------------------------------
/flyweight-pattern/example2/solution/interfaces/stats.interface.ts:
--------------------------------------------------------------------------------
1 | export interface IStats {
2 | goals: number;
3 | assists: number;
4 | passes: number;
5 | };
--------------------------------------------------------------------------------
/flyweight-pattern/example2/solution/models/stats.ts:
--------------------------------------------------------------------------------
1 | export class Stats {
2 | constructor(public goals: number, public assists: number, public matches: number) {}
3 | }
--------------------------------------------------------------------------------
/proxy-pattern/example2/subjects/subject-cache.interface.ts:
--------------------------------------------------------------------------------
1 | // Common Interface
2 | export interface SubjectCache {
3 | request(resource: string): Promise;
4 | }
--------------------------------------------------------------------------------
/demeter/nodemon-example1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/facade-pattern/example2/problem/dragonball/models/namekian.ts:
--------------------------------------------------------------------------------
1 | export class Namekian {
2 | public getPower(): number {
3 | return Math.random() * 20 + 20;
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/bridge-pattern/nodemon-example1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/command-pattern/example1/problem/index.ts:
--------------------------------------------------------------------------------
1 | import { Agent } from './agent.class';
2 |
3 | const agent = new Agent();
4 | agent.placeOrder('buy');
5 | agent.placeOrder('sell');
6 |
--------------------------------------------------------------------------------
/observer-pattern/example1/observer.interface.ts:
--------------------------------------------------------------------------------
1 | import { Subject } from "./subject.interface";
2 |
3 | export interface Observer {
4 | update(subject: Subject): void;
5 | }
6 |
--------------------------------------------------------------------------------
/proxy-pattern/nodemon-example1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/state-pattern/example1/problem/index.ts:
--------------------------------------------------------------------------------
1 | import { Context } from "./context";
2 |
3 | const context = new Context();
4 | context.request('request1');
5 | context.request('request2');
--------------------------------------------------------------------------------
/adapter-pattern/nodemon-example1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/adapter-pattern/nodemon-example2.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example2/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/composite-pattern/nodemon-example1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/flyweight-pattern/nodemon-example1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/mediator-pattern/example1/mediator.ts:
--------------------------------------------------------------------------------
1 | import { Colleague } from "./colleague";
2 |
3 | export interface Mediator {
4 | notify(sender: Colleague, event: string): void;
5 | }
6 |
--------------------------------------------------------------------------------
/mediator-pattern/nodemon-example1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/observer-pattern/nodemon-example1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/observer-pattern/nodemon-example2.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example2/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/prototype-pattern/nodemon-example1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/abstract-factory-pattern/nodemon-example1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/abstract-factory-pattern/nodemon-example2.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example2/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/decorator-pattern/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "lib": ["es2015", "dom"],
5 | "strict": false,
6 | "declaration": true
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/facade-pattern/example2/facade-solution/dragonball/models/namekian.model.ts:
--------------------------------------------------------------------------------
1 | export class Namekian {
2 | public getPower(): number {
3 | return Math.random() * 20 + 20;
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/factory-method-pattern/nodemon-example1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/factory-method-pattern/nodemon-example2.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example2/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/factory-method-pattern/nodemon-example3.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example3"],
3 | "ext": "ts",
4 | "ignore": ["example3/**/*.spec.ts"],
5 | "exec": "ts-node ./example3/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/factory-method-pattern/nodemon-example4.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example4"],
3 | "ext": "ts",
4 | "ignore": ["example4/**/*.spec.ts"],
5 | "exec": "ts-node ./example4/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/iterator-pattern/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "lib": ["es2015", "dom"],
5 | "strict": false,
6 | "declaration": true
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/mediator-pattern/example1/colleague.ts:
--------------------------------------------------------------------------------
1 | import { Mediator } from "./mediator";
2 |
3 | export interface Colleague {
4 | setMediator(mediator: Mediator): void;
5 | action(): void;
6 | }
--------------------------------------------------------------------------------
/proxy-pattern/nodemon-example2-problem.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/state-pattern/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ES2017",
4 | "lib": ["es2015", "dom"],
5 | "strict": false,
6 | "declaration": true
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/bridge-pattern/nodemon-example2-solve.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/problem/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/chain-responsibility-pattern/nodemon-example1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/chain-responsibility-pattern/nodemon-example2.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example2/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/proxy-pattern/nodemon-example2-solve.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/solution/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/state-pattern/nodemon-example1-problem.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/problem/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/state-pattern/nodemon-example2-problem.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example2/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/problem/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/bridge-pattern/nodemon-example2-problem.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/problem/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/command-pattern/nodemon-example1-problem.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/problem/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/composite-pattern/nodemon-example2-problem.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/problem/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/composite-pattern/nodemon-example2-solve.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/solution/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/decorator-pattern/nodemon-example1-problem.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/problem/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/facade-pattern/nodemon-example1-problem.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/problem/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/facade-pattern/nodemon-example2-problem.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example2/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/problem/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/flyweight-pattern/example2/problem/models/index.ts:
--------------------------------------------------------------------------------
1 | export { Player } from './player';
2 | export { Position } from './position';
3 | export { Stats } from './stats';
4 | export { Team } from './team';
--------------------------------------------------------------------------------
/flyweight-pattern/example2/solution/models/index.ts:
--------------------------------------------------------------------------------
1 | export { Player } from "./player";
2 | export { Position } from "./position";
3 | export { Stats } from "./stats";
4 | export { Team } from "./team";
--------------------------------------------------------------------------------
/flyweight-pattern/nodemon-example2-problem.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/problem/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/flyweight-pattern/nodemon-example2-solve.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/solution/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/iterator-pattern/nodemon-example1-problem.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/problem/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/mediator-pattern/nodemon-example2-problem.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/problem/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/mediator-pattern/nodemon-example2-solve.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/solution/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/observer-pattern/README.md:
--------------------------------------------------------------------------------
1 | # Design Patterns: Observer (Design Patterns series)
2 |
3 | **To read an explanation of this design pattern, check out the [blogpost](https://www.carloscaballero.io/).**
4 |
--------------------------------------------------------------------------------
/prototype-pattern/nodemon-example2-problem.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/problem/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/prototype-pattern/nodemon-example2-solve.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/solution/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/singleton-pattern/nodemon-example1-problem.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/problem/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/singleton-pattern/nodemon-example2-problem.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example2/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/problem/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/iterators-javascript/nodemon-example1-problem.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/problem/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/null-object-pattern/nodemon-example1-problem.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/problem/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/state-pattern/nodemon-example2-state-solution-1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example2/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/solution/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/state-pattern/README.md:
--------------------------------------------------------------------------------
1 | # Design Patterns: State (Design Patterns series)
2 |
3 | **To read an explanation of this design pattern, check out the [blogpost](https://www.carloscaballero.io/design-patterns-state/).**
--------------------------------------------------------------------------------
/state-pattern/nodemon-example1-state-solution-1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/solution-1/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/command-pattern/example2/command-solution-1/commands/index.ts:
--------------------------------------------------------------------------------
1 | export * from './command.class';
2 | export * from './save-secret-command';
3 | export * from './clean-command';
4 | export * from './move-command';
5 |
--------------------------------------------------------------------------------
/composite-pattern/example1/leaf.ts:
--------------------------------------------------------------------------------
1 | import { Component } from "./component";
2 |
3 | export class Leaf implements Component {
4 | operation(): void {
5 | console.log("Leaf operation.");
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/demeter/example1/interfaces/person.interface.ts:
--------------------------------------------------------------------------------
1 | import { IHouse } from './house.interface';
2 |
3 | export interface IPerson {
4 | getName(): String;
5 | getHouse(): IHouse;
6 | getZipCode(): String;
7 | }
8 |
--------------------------------------------------------------------------------
/facade-pattern/README.md:
--------------------------------------------------------------------------------
1 | # Design Patterns: Facade (Design Patterns series)
2 |
3 | **To read an explanation of this design pattern, check out the [blogpost](https://www.carloscaballero.io/design-patterns-facade/).**
--------------------------------------------------------------------------------
/facade-pattern/example1/problem/system1/classA2.ts:
--------------------------------------------------------------------------------
1 | import { ClassA } from './classA';
2 |
3 | export class ClassA2 extends ClassA {
4 | methodA2() {
5 | console.log('MethodA2 from ClassA2');
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/facade-pattern/example1/problem/system2/classC3.ts:
--------------------------------------------------------------------------------
1 | import { ClassC } from './classC';
2 |
3 | export class ClassC3 extends ClassC {
4 | methodC3() {
5 | console.log('methodC3 from ClassC3');
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/facade-pattern/nodemon-example2-facade-solution-1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example2/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/facade-solution/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/iterator-pattern/README.md:
--------------------------------------------------------------------------------
1 | # Design Patterns: Facade (Design Patterns series)
2 |
3 | **To read an explanation of this design pattern, check out the [blogpost](https://www.carloscaballero.io/design-patterns-facade/).**
--------------------------------------------------------------------------------
/adapter-pattern/README.md:
--------------------------------------------------------------------------------
1 | # Design Patterns: Adapter (Design Patterns series)
2 |
3 | **To read an explanation of this design pattern, check out the [blogpost](https://www.carloscaballero.io/design-patterns-adapter/).**
--------------------------------------------------------------------------------
/command-pattern/README.md:
--------------------------------------------------------------------------------
1 | # Design Patterns: Facade (Design Patterns series)
2 |
3 | **To read an explanation of this design pattern, check out the [blogpost](https://www.carloscaballero.io/design-patterns-command/).**
4 |
--------------------------------------------------------------------------------
/command-pattern/nodemon-example1-command-solution-1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/command-solution-1/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/command-pattern/nodemon-example2-command-solution-1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example2/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/command-solution-1/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/facade-pattern/nodemon-example1-facade-solution-1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/facade-solution-1/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/facade-pattern/nodemon-example1-facade-solution-2.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/facade-solution-2/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/iterator-pattern/nodemon-example2-iterator-solution-1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example2/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/iterator-solution/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/iterators-javascript/README.md:
--------------------------------------------------------------------------------
1 | # Design Patterns: Facade (Design Patterns series)
2 |
3 | **To read an explanation of this design pattern, check out the [blogpost](https://www.carloscaballero.io/design-patterns-facade/).**
--------------------------------------------------------------------------------
/null-object-pattern/nodemon-example1-solution-1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/null-object-solution-1/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/observer-pattern/example2/auctioneer.interface.ts:
--------------------------------------------------------------------------------
1 | import { Agent } from "./agent.interface";
2 |
3 | export interface Auctioneer {
4 | name: string;
5 | MAX_LIMIT: number;
6 | update(agent: Agent): void;
7 | }
8 |
--------------------------------------------------------------------------------
/bridge-pattern/example1/implementor.ts:
--------------------------------------------------------------------------------
1 | // Este es el Implementor en el patrón Bridge. Define la interfaz para las implementaciones concretas.
2 | export interface Implementor {
3 | operationImplementation(): void;
4 | }
5 |
--------------------------------------------------------------------------------
/decorator-pattern/nodemon-example1-decorator-solution-1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/decorator-solution-1/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/decorator-pattern/nodemon-example2-decorator-solution-1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example2/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/decorator-solution/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/facade-pattern/example1/facade-solution-1/system1/classA2.ts:
--------------------------------------------------------------------------------
1 | import { ClassA } from './classA';
2 |
3 | export class ClassA2 extends ClassA {
4 | methodA2() {
5 | console.log('MethodA2 from ClassA2');
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/facade-pattern/example1/facade-solution-2/system1/classA2.ts:
--------------------------------------------------------------------------------
1 | import { ClassA } from './classA';
2 |
3 | export class ClassA2 extends ClassA {
4 | methodA2() {
5 | console.log('MethodA2 from ClassA2');
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/facade-pattern/example1/facade-solution-2/system2/classC3.ts:
--------------------------------------------------------------------------------
1 | import { ClassC } from './classC';
2 |
3 | export class ClassC3 extends ClassC {
4 | methodC3() {
5 | console.log('methodC3 from ClassC3');
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/iterator-pattern/nodemon-example1-iterator-solution-1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/iterator-solution-1/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/iterators-javascript/nodemon-example2-iterator-solution-1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example2/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/iterator-solution/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/null-object-pattern/README.md:
--------------------------------------------------------------------------------
1 | # Design Patterns: Facade (Design Patterns series)
2 |
3 | **To read an explanation of this design pattern, check out the [blogpost](https://www.carloscaballero.io/design-patterns-command/).**
4 |
--------------------------------------------------------------------------------
/singleton-pattern/nodemon-example1-singleton-solution-1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/singleton-solution-1/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/singleton-pattern/nodemon-example2-singleton-solution-1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example2"],
3 | "ext": "ts",
4 | "ignore": ["example2/**/*.spec.ts"],
5 | "exec": "ts-node ./example2/singleton-solution/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/chain-responsibility-pattern/README.md:
--------------------------------------------------------------------------------
1 | # Design Patterns: Chain of Responsibility (Design Patterns series)
2 |
3 | **To read an explanation of this design pattern, check out the [blogpost](https://www.carloscaballero.io/).**
4 |
--------------------------------------------------------------------------------
/decorator-pattern/README.md:
--------------------------------------------------------------------------------
1 | # Design Patterns: Decorator (Design Patterns series)
2 |
3 | **To read an explanation of this design pattern, check out the [blogpost](https://www.carloscaballero.io/design-patterns-decorator/).**
4 |
--------------------------------------------------------------------------------
/factory-method-pattern/example2/burger.model.ts:
--------------------------------------------------------------------------------
1 | import { Product } from "./product.interface";
2 |
3 | export class Burger implements Product {
4 | public operation(): string {
5 | return "Burger: Results";
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/factory-method-pattern/example2/kebab.model.ts:
--------------------------------------------------------------------------------
1 | import { Product } from "./product.interface";
2 |
3 | export class Kebab implements Product {
4 | public operation(): string {
5 | return 'Kebab: Operation';
6 | }
7 | }
--------------------------------------------------------------------------------
/factory-method-pattern/example2/pizza.model.ts:
--------------------------------------------------------------------------------
1 | import { Product } from "./product.interface";
2 |
3 | export class Pizza implements Product {
4 | public operation(): string {
5 | return 'Pizza: Operation';
6 | }
7 | }
--------------------------------------------------------------------------------
/factory-method-pattern/example3/kebab.model.ts:
--------------------------------------------------------------------------------
1 | import { Product } from "./product.interface";
2 |
3 | export class Kebab implements Product {
4 | public operation(): string {
5 | return 'Kebab: Operation';
6 | }
7 | }
--------------------------------------------------------------------------------
/factory-method-pattern/example3/pizza.model.ts:
--------------------------------------------------------------------------------
1 | import { Product } from "./product.interface";
2 |
3 | export class Pizza implements Product {
4 | public operation(): string {
5 | return 'Pizza: Operation';
6 | }
7 | }
--------------------------------------------------------------------------------
/iterators-javascript/nodemon-example1-iterator-solution-1.json:
--------------------------------------------------------------------------------
1 | {
2 | "watch": ["example1"],
3 | "ext": "ts",
4 | "ignore": ["example1/**/*.spec.ts"],
5 | "exec": "ts-node ./example1/iterator-solution-1/index.ts"
6 | }
7 |
--------------------------------------------------------------------------------
/singleton-pattern/README.md:
--------------------------------------------------------------------------------
1 | # Design Patterns: Singleton (Design Patterns series)
2 |
3 | **To read an explanation of this design pattern, check out the [blogpost](https://www.carloscaballero.io/design-patterns-singleton/).**
4 |
--------------------------------------------------------------------------------
/understanding-this-in-js/03-keyword-new/new-01.js:
--------------------------------------------------------------------------------
1 | function Dog() {
2 | //this context is not windows
3 | console.log('this is not a global scope')
4 | console.log(this === module.exports);
5 | }
6 |
7 | new Dog();
8 |
--------------------------------------------------------------------------------
/adapter-pattern/example1/models/android.model.ts:
--------------------------------------------------------------------------------
1 | export class Android {
2 | public punch(): number {
3 | return 10;
4 | }
5 | public kick(): number {
6 | return Math.random() * this.punch() + this.punch();
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/chain-responsibility-pattern/example2/interfaces/handler.ts:
--------------------------------------------------------------------------------
1 | import { User } from "./user.interface";
2 |
3 | export interface Handler {
4 | setNextMiddleware(handler: Handler): void;
5 |
6 | execute(user: User): boolean;
7 | }
8 |
--------------------------------------------------------------------------------
/factory-method-pattern/example3/burger.model.ts:
--------------------------------------------------------------------------------
1 | import { Product } from "./product.interface";
2 |
3 | export class Burger implements Product {
4 | public operation(): string {
5 | return 'Burger: Results';
6 | }
7 | }
--------------------------------------------------------------------------------
/strategy-pattern/README.md:
--------------------------------------------------------------------------------
1 | # Design Patterns: Strategy (Design Patterns series)
2 |
3 | **To read an explanation of this design pattern, check out the [blogpost](https://www.carloscaballero.io/stategy-pattern-in-javascript-typescript/).**
--------------------------------------------------------------------------------
/understanding-this-in-js/README.md:
--------------------------------------------------------------------------------
1 | # Design Patterns: Singleton (Design Patterns series)
2 |
3 | **To read an explanation of this design pattern, check out the [blogpost](https://www.carloscaballero.io/design-patterns-singleton/).**
4 |
--------------------------------------------------------------------------------
/abstract-factory-pattern/example2/weapons/axe.model.ts:
--------------------------------------------------------------------------------
1 | import { Weapon } from "./weapon.interface";
2 |
3 | export class Axe implements Weapon {
4 | public usefulFunction(): string {
5 | return "The result of the Axe";
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/adapter-pattern/example2/models/saiyan.model.ts:
--------------------------------------------------------------------------------
1 | export class Saiyan {
2 | myPowerPart1(): number {
3 | return Math.random() * 100 + 100;
4 | }
5 | myPowerPart2(): number {
6 | return Math.random() * 1000 + 500;
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/command-pattern/example2/command-solution-1/services/store.service.ts:
--------------------------------------------------------------------------------
1 | export class StoreService {
2 | constructor() {}
3 | storeMessage(message: string) {
4 | console.log('StoreService -> StoreMessage: ', message);
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/iterator-pattern/example2/iterator-solution/profile-iterator.interface.ts:
--------------------------------------------------------------------------------
1 | import { Profile } from './profile.class';
2 |
3 | export interface ProfileIterator {
4 | hasNext(): boolean;
5 | getNext(): Profile;
6 | reset(): void;
7 | }
8 |
--------------------------------------------------------------------------------
/observer-pattern/example1/subject.interface.ts:
--------------------------------------------------------------------------------
1 | import { Observer } from "./observer.interface";
2 |
3 | export interface Subject {
4 | attach(observer: Observer): void;
5 | detach(observer: Observer): void;
6 | notify(): void;
7 | }
8 |
--------------------------------------------------------------------------------
/template-method-pattern/README.md:
--------------------------------------------------------------------------------
1 | # Design Patterns: Template Method (Design Patterns series)
2 |
3 | **To read an explanation of this design pattern, check out the [blogpost](https://www.carloscaballero.io/design-patterns-template-method/).**
--------------------------------------------------------------------------------
/workshop-javascript/problems/Problem3/css/rope.css:
--------------------------------------------------------------------------------
1 | .field {
2 | width: 75%;
3 | height: 75%;
4 | position: absolute;
5 | }
6 | .rope {
7 | position: absolute;
8 | width: 30%;
9 | padding: 0%;
10 | margin: 0;
11 | }
12 |
--------------------------------------------------------------------------------
/workshop-javascript/solutions/Problem3/css/rope.css:
--------------------------------------------------------------------------------
1 | .field {
2 | width: 75%;
3 | height: 75%;
4 | position: absolute;
5 | }
6 | .rope {
7 | position: absolute;
8 | width: 30%;
9 | padding: 0%;
10 | margin: 0;
11 | }
12 |
--------------------------------------------------------------------------------
/abstract-factory-pattern/README.md:
--------------------------------------------------------------------------------
1 | # Design Patterns: Factory Method (Design Patterns series)
2 |
3 | **To read an explanation of this design pattern, check out the [blogpost](https://www.carloscaballero.io/design-patterns-factory-method/).**
4 |
--------------------------------------------------------------------------------
/decorator-pattern/example1/problem/component-base.ts:
--------------------------------------------------------------------------------
1 | import { Component } from './component.interface';
2 |
3 | export class ComponentBase implements Component {
4 | public operation(): string {
5 | return 'ComponentBase';
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/demeter/example1/interfaces/address.interface.ts:
--------------------------------------------------------------------------------
1 | export interface IAddress {
2 | getZipCode(): string;
3 | getNumber(): string;
4 | getStreet(): string;
5 | getCity(): string;
6 | getState(): string;
7 | getCounty(): string;
8 | }
9 |
--------------------------------------------------------------------------------
/demeter/example1/interfaces/house.interface.ts:
--------------------------------------------------------------------------------
1 | import { IAddress } from './address.interface';
2 |
3 | export interface IHouse {
4 | getAddress(): IAddress;
5 | getColor(): string;
6 | getSize(): number;
7 | getZipCode(): string;
8 | }
9 |
--------------------------------------------------------------------------------
/factory-method-pattern/README.md:
--------------------------------------------------------------------------------
1 | # Design Patterns: Factory Method (Design Patterns series)
2 |
3 | **To read an explanation of this design pattern, check out the [blogpost](https://www.carloscaballero.io/design-patterns-factory-method/).**
4 |
--------------------------------------------------------------------------------
/iterators-javascript/example2/iterator-solution/profile-iterator.interface.ts:
--------------------------------------------------------------------------------
1 | import { Profile } from './profile.class';
2 |
3 | export interface ProfileIterator {
4 | hasNext(): boolean;
5 | next(): Profile;
6 | reset(): void;
7 | }
8 |
--------------------------------------------------------------------------------
/abstract-factory-pattern/example2/armor/armor-interface.ts:
--------------------------------------------------------------------------------
1 | import { Weapon } from "../weapons/weapon.interface";
2 |
3 | export interface Armor {
4 | usefulFunction(): string;
5 | usefulFunctionWithWeapon(collaborator: Weapon): string;
6 | }
7 |
--------------------------------------------------------------------------------
/abstract-factory-pattern/example2/weapons/sword.model.ts:
--------------------------------------------------------------------------------
1 | import { Weapon } from "./weapon.interface";
2 |
3 | export class Sword implements Weapon {
4 | public usefulFunction(): string {
5 | return "The result of the Sword";
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/iterator-pattern/example1/iterator-solution-1/agregator.interface.ts:
--------------------------------------------------------------------------------
1 | import { Iterator } from './iterator.interface';
2 |
3 | export interface Aggregator {
4 | getIterator(): Iterator;
5 | getReverseIterator(): Iterator;
6 | }
7 |
--------------------------------------------------------------------------------
/factory-method-pattern/example1/concrete-product1.ts:
--------------------------------------------------------------------------------
1 | import { Product } from "./product.interface";
2 |
3 | export class ConcreteProduct1 implements Product {
4 | public operation(): string {
5 | return "ConcreteProduct1: Operation";
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/factory-method-pattern/example1/concrete-product2.ts:
--------------------------------------------------------------------------------
1 | import { Product } from "./product.interface";
2 |
3 | export class ConcreteProduct2 implements Product {
4 | public operation(): string {
5 | return "ConcreteProduct2: Operation";
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/proxy-pattern/example2/subjects/real-subject.ts:
--------------------------------------------------------------------------------
1 | import { Subject } from "./subject.interface";
2 |
3 | export class RealSubject implements Subject {
4 | operation(): void {
5 | console.log('RealSubject: Handling operation.');
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/decorator-pattern/example1/problem/component-a.ts:
--------------------------------------------------------------------------------
1 | import { ComponentBase } from './component-base';
2 |
3 | export class ComponentA extends ComponentBase {
4 | public operation(): string {
5 | return `ComponentA(${super.operation()})`;
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/decorator-pattern/example1/problem/component-b.ts:
--------------------------------------------------------------------------------
1 | import { ComponentBase } from './component-base';
2 |
3 | export class ComponentB extends ComponentBase {
4 | public operation(): string {
5 | return `ComponentB(${super.operation()})`;
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/decorator-pattern/example1/problem/component-ba.ts:
--------------------------------------------------------------------------------
1 | import { ComponentBase } from './component-base';
2 |
3 | export class ComponentBA extends ComponentBase {
4 | public operation(): string {
5 | return `ComponentBA(${super.operation()})`;
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/decorator-pattern/example1/problem/component-c.ts:
--------------------------------------------------------------------------------
1 | import { ComponentBase } from './component-base';
2 |
3 | export class ComponentC extends ComponentBase {
4 | public operation(): string {
5 | return `ComponentC(${super.operation()})`;
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/decorator-pattern/example1/problem/component-ca.ts:
--------------------------------------------------------------------------------
1 | import { ComponentBase } from './component-base';
2 |
3 | export class ComponentCA extends ComponentBase {
4 | public operation(): string {
5 | return `ComponentCA(${super.operation()})`;
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/facade-pattern/example2/problem/dragonball/models/saiyan.model.ts:
--------------------------------------------------------------------------------
1 | export class Saiyan {
2 | myPowerPart1(): number {
3 | return Math.random() * 100 + 100;
4 | }
5 | myPowerPart2(): number {
6 | return Math.random() * 1000 + 500;
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/null-object-pattern/example1/null-object-solution-1/saiyan.class.ts:
--------------------------------------------------------------------------------
1 | export abstract class AbstractSaiyan {
2 | protected name: string;
3 | protected power: number;
4 | public abstract getName(): string;
5 | public abstract toString(): string;
6 | }
7 |
--------------------------------------------------------------------------------
/observer-pattern/example2/agent.interface.ts:
--------------------------------------------------------------------------------
1 | import { Auctioneer } from "./auctioneer.interface";
2 |
3 | export interface Agent {
4 | subscribe(auctioneer: Auctioneer): void;
5 | unsubscribe(auctioneer: Auctioneer): void;
6 | notify(): void;
7 | }
8 |
--------------------------------------------------------------------------------
/proxy-pattern/example2/subjects/index.ts:
--------------------------------------------------------------------------------
1 | export { Subject } from './subject.interface';
2 | export { RealSubject } from './real-subject';
3 | export { SubjectCache } from './subject-cache.interface';
4 | export { RealSubjectCache } from './real-subject-cache';
--------------------------------------------------------------------------------
/command-pattern/example1/problem/stock.trader.class.ts:
--------------------------------------------------------------------------------
1 | // Receiver class.
2 | export class StockTrade {
3 | buy() {
4 | console.log('You want to buy stocks');
5 | }
6 | sell() {
7 | console.log('You want to sell stocks ');
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/decorator-pattern/example1/problem/component-cba.ts:
--------------------------------------------------------------------------------
1 | import { ComponentBase } from './component-base';
2 |
3 | export class ComponentCBA extends ComponentBase {
4 | public operation(): string {
5 | return `ComponentCBA(${super.operation()})`;
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/facade-pattern/example2/facade-solution/dragonball/models/saiyan.model.ts:
--------------------------------------------------------------------------------
1 | export class Saiyan {
2 | myPowerPart1(): number {
3 | return Math.random() * 100 + 100;
4 | }
5 | myPowerPart2(): number {
6 | return Math.random() * 1000 + 500;
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/abstract-factory-pattern/example2/abstract-factory.ts:
--------------------------------------------------------------------------------
1 | import { Armor } from "./armor/armor-interface";
2 | import { Weapon } from "./weapons/weapon.interface";
3 |
4 | export interface AbstractFactory {
5 | createWeapon(): Weapon;
6 | createArmor(): Armor;
7 | }
8 |
--------------------------------------------------------------------------------
/abstract-factory-pattern/example2/weapons/mage-fireball.model.ts:
--------------------------------------------------------------------------------
1 | import { Weapon } from "./weapon.interface";
2 |
3 | export class MageFireball implements Weapon {
4 | public usefulFunction(): string {
5 | return "The result of the MageFireball";
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/decorator-pattern/example1/decorator-solution-1/concrete-component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from './component.interface';
2 |
3 | export class ConcreteComponent implements Component {
4 | public operation(): string {
5 | return 'ConcreteComponent';
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/iterators-javascript/example1/iterator-solution-1/agregator.interface.ts:
--------------------------------------------------------------------------------
1 | import { CustomIterator } from './iterator.interface';
2 |
3 | export interface Aggregator {
4 | getIterator(): CustomIterator;
5 | getReverseIterator(): CustomIterator;
6 | }
7 |
--------------------------------------------------------------------------------
/state-pattern/example1/state-solution-1/index.ts:
--------------------------------------------------------------------------------
1 | import { ConcreteStateA } from "./concrete-state-A";
2 | import { Context } from "./context";
3 |
4 | const context = new Context(new ConcreteStateA()); // Initial State
5 | context.request1();
6 | context.request2();
7 |
--------------------------------------------------------------------------------
/command-pattern/example1/command-solution-1/stock.trader.class.ts:
--------------------------------------------------------------------------------
1 | // Receiver class.
2 | export class StockTrade {
3 | buy() {
4 | console.log('You want to buy stocks');
5 | }
6 | sell() {
7 | console.log('You want to sell stocks ');
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/proxy-pattern/example2/proxies/index.ts:
--------------------------------------------------------------------------------
1 | export { AccessProxy } from './access.proxy';
2 | export { LoggingProxy } from './logging.proxy';
3 | export { CacheProxy } from './cache.proxy';
4 | export { LazyProxy } from './lazy.proxy';
5 | export { RemoteProxy } from './remote.proxy';
--------------------------------------------------------------------------------
/abstract-factory-pattern/example1/concrete-productA1.ts:
--------------------------------------------------------------------------------
1 | import { AbstractProductA } from "./abstract-productA";
2 |
3 | export class ConcreteProductA1 implements AbstractProductA {
4 | public usefulFunctionA(): string {
5 | return "The result of the product A1.";
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/abstract-factory-pattern/example1/concrete-productA2.ts:
--------------------------------------------------------------------------------
1 | import { AbstractProductA } from "./abstract-productA";
2 |
3 | export class ConcreteProductA2 implements AbstractProductA {
4 | public usefulFunctionA(): string {
5 | return "The result of the product A2.";
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/abstract-factory-pattern/example1/concrete-productB1.ts:
--------------------------------------------------------------------------------
1 | import { AbstractProductB } from "./abstract-productB";
2 |
3 | export class ConcreteProductB1 implements AbstractProductB {
4 | public usefulFunctionB(): string {
5 | return "The result of the product B1.";
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/abstract-factory-pattern/example1/concrete-productB2.ts:
--------------------------------------------------------------------------------
1 | import { AbstractProductB } from "./abstract-productB";
2 |
3 | export class ConcreteProductB2 implements AbstractProductB {
4 | public usefulFunctionB(): string {
5 | return "The result of the product B2.";
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/decorator-pattern/example1/decorator-solution-1/concrete-decorator-a.ts:
--------------------------------------------------------------------------------
1 | import { Decorator } from './decorator';
2 |
3 | export class ConcreteDecoratorA extends Decorator {
4 | public operation(): string {
5 | return `ConcreteDecoratorA(${super.operation()})`;
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/decorator-pattern/example1/decorator-solution-1/concrete-decorator-b.ts:
--------------------------------------------------------------------------------
1 | import { Decorator } from './decorator';
2 |
3 | export class ConcreteDecoratorB extends Decorator {
4 | public operation(): string {
5 | return `ConcreteDecoratorB(${super.operation()})`;
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/decorator-pattern/example1/decorator-solution-1/concrete-decorator-c.ts:
--------------------------------------------------------------------------------
1 | import { Decorator } from './decorator';
2 |
3 | export class ConcreteDecoratorC extends Decorator {
4 | public operation(): string {
5 | return `ConcreteDecoratorC(${super.operation()})`;
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/mediator-pattern/example2/solution/sensor.ts:
--------------------------------------------------------------------------------
1 | import { IoTDevice } from "./iot-device";
2 | import { IoTMediator } from "./iot-mediator";
3 |
4 | export class Sensor extends IoTDevice {
5 | constructor(id: string, mediator: IoTMediator) {
6 | super(id, mediator);
7 | }
8 | }
--------------------------------------------------------------------------------
/adapter-pattern/example1/models/namekian.ts:
--------------------------------------------------------------------------------
1 | import { Warrior } from '../interfaces/warrior.interface';
2 |
3 | export class Namekian implements Warrior {
4 | public ATTACK_BASE = 50;
5 | public attack(): number {
6 | return Math.random() * 50 + this.ATTACK_BASE;
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/adapter-pattern/example1/models/saiyan.model.ts:
--------------------------------------------------------------------------------
1 | import { Warrior } from '../interfaces/warrior.interface';
2 |
3 | export class Saiyan implements Warrior {
4 | public ATTACK_BASE = 100;
5 | public attack(): number {
6 | return Math.random() * 100 + this.ATTACK_BASE;
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/state-pattern/example2/problem/state.enum.ts:
--------------------------------------------------------------------------------
1 | export enum State {
2 | TRANSFORMATION1 = 'transformation1',
3 | TRANSFORMATION2 = 'transformation2',
4 | TRANSFORMATION3 = 'transformation3',
5 | TRANSFORMATION4 = 'transformation4',
6 | GOLDEN_FREEZER = 'golden_freezer',
7 | }
--------------------------------------------------------------------------------
/chain-responsibility-pattern/example2/middlewares/index.ts:
--------------------------------------------------------------------------------
1 | export { RoleMiddleware } from "./role.middleware";
2 | export { ThrottlingMiddleware } from "./throttling.middleware";
3 | export { UserExistsMiddleware } from "./user-exists.middleware";
4 | export { Middleware } from "./middleware";
5 |
--------------------------------------------------------------------------------
/command-pattern/example2/command-solution-1/commands/command.class.ts:
--------------------------------------------------------------------------------
1 | export abstract class Command {
2 | protected uid = Math.floor(Math.random() * 100000);
3 |
4 | public toString(): string {
5 | return 'R2D2: Command UID:: ' + this.uid;
6 | }
7 | abstract execute(args): void;
8 | }
9 |
--------------------------------------------------------------------------------
/abstract-factory-pattern/example1/abstract-factory.ts:
--------------------------------------------------------------------------------
1 | import { AbstractProductA } from "./abstract-productA";
2 | import { AbstractProductB } from "./abstract-productB";
3 |
4 | export interface AbstractFactory {
5 | createProductA(): AbstractProductA;
6 | createProductB(): AbstractProductB;
7 | }
8 |
--------------------------------------------------------------------------------
/command-pattern/example2/command-solution-1/services/r2d2.service.ts:
--------------------------------------------------------------------------------
1 | export class R2D2Service {
2 | constructor() {}
3 | clean() {
4 | console.log('R2D2Service -> Clean ');
5 | }
6 | move(direction: string) {
7 | console.log('R2D2Service -> Move: ', direction);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/iterator-pattern/example1/problem/words-collection.ts:
--------------------------------------------------------------------------------
1 | export class WordsCollection {
2 | private items: string[] = [];
3 |
4 | public getItems(): string[] {
5 | return this.items;
6 | }
7 |
8 | public addItem(item: string): void {
9 | this.items.push(item);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/iterators-javascript/example1/problem/words-collection.ts:
--------------------------------------------------------------------------------
1 | export class WordsCollection {
2 | private items: string[] = [];
3 |
4 | public getItems(): string[] {
5 | return this.items;
6 | }
7 |
8 | public addItem(item: string): void {
9 | this.items.push(item);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/command-pattern/example1/command-solution-1/order.class.ts:
--------------------------------------------------------------------------------
1 | export abstract class Order {
2 | protected uid = Math.floor(Math.random() * 100000);
3 | protected type: string;
4 | public toString(): string {
5 | return 'UID: ' + this.uid + ' - Operation: ' + this.type;
6 | }
7 | abstract execute();
8 | }
9 |
--------------------------------------------------------------------------------
/factory-method-pattern/example3/kebab-creator.ts:
--------------------------------------------------------------------------------
1 | import { Creator } from "./creator";
2 | import { Kebab } from "./kebab.model";
3 | import { Product } from "./product.interface";
4 |
5 | export class KebabCreator extends Creator {
6 | public factoryMethod(): Product {
7 | return new Kebab();
8 | }
9 | }
--------------------------------------------------------------------------------
/factory-method-pattern/example3/pizza-creator.ts:
--------------------------------------------------------------------------------
1 | import { Creator } from "./creator";
2 | import { Pizza } from "./pizza.model";
3 | import { Product } from "./product.interface";
4 |
5 | export class PizzaCreator extends Creator {
6 | public factoryMethod(): Product {
7 | return new Pizza();
8 | }
9 | }
--------------------------------------------------------------------------------
/iterator-pattern/example2/iterator-solution/social-network.interface.ts:
--------------------------------------------------------------------------------
1 | import { ProfileIterator } from './profile-iterator.interface';
2 |
3 | export interface SocialNetwork {
4 | createFriendsIterator(profileEmail: string): ProfileIterator;
5 | createCoworkersIterator(profileEmail: string): ProfileIterator;
6 | }
7 |
--------------------------------------------------------------------------------
/factory-method-pattern/example3/burger-creator.ts:
--------------------------------------------------------------------------------
1 | import { Burger } from "./burger.model";
2 | import { Creator } from "./creator";
3 | import { Product } from "./product.interface";
4 |
5 | export class BurgerCreator extends Creator {
6 | public factoryMethod(): Product {
7 | return new Burger();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/decorator-pattern/example2/decorator-solution/character.interface.ts:
--------------------------------------------------------------------------------
1 | export interface Character {
2 | attack(): number;
3 | defend(): number;
4 | isAlive(): boolean;
5 | setLife(life: number): void;
6 | getLife(): number;
7 | getName(): string;
8 | toString(): string;
9 | receiveHit(attack: number): void;
10 | }
11 |
--------------------------------------------------------------------------------
/factory-method-pattern/example1/creator.ts:
--------------------------------------------------------------------------------
1 | import { Product } from "./product.interface";
2 |
3 | export abstract class Creator {
4 | protected abstract factoryMethod(): Product;
5 |
6 | public operation(): string {
7 | const product = this.factoryMethod();
8 | return `Creator: ${product.operation()}`;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/bridge-pattern/example1/concrete-implementorB.ts:
--------------------------------------------------------------------------------
1 | // Otra implementación concreta de Implementor.
2 | import { Implementor } from './implementor';
3 |
4 | export class ConcreteImplementorB implements Implementor {
5 | operationImplementation(): void {
6 | console.log("ConcreteImplementorB operation implementation.");
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/bridge-pattern/example1/concrete-implementorA.ts:
--------------------------------------------------------------------------------
1 | // Esta es una implementación concreta de Implementor.
2 | import { Implementor } from './implementor';
3 |
4 | export class ConcreteImplementorA implements Implementor {
5 | operationImplementation(): void {
6 | console.log("ConcreteImplementorA operation implementation.");
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/chain-responsibility-pattern/example2/app.constants.ts:
--------------------------------------------------------------------------------
1 | export const USERS = {
2 | ADMIN: {
3 | email: "admin@example.com",
4 | password: "admin",
5 | },
6 | USER: {
7 | email: "user@example.com",
8 | password: "user",
9 | },
10 | };
11 |
12 | export const REQUEST_PER_MINUTE = 2;
13 | export const WAIT_TIME = 60_000;
14 |
--------------------------------------------------------------------------------
/iterators-javascript/example1/iterator-solution-1/iterator.interface.ts:
--------------------------------------------------------------------------------
1 | export interface CustomIterator {
2 | // Return the current element.
3 | current(): T;
4 |
5 | // Return the current element and move forward to next element.
6 | next(): T;
7 |
8 | // Checks if current position is valid.
9 | hasMoreElements(): boolean;
10 | }
11 |
--------------------------------------------------------------------------------
/prototype-pattern/example1/concrete-prototype2.ts:
--------------------------------------------------------------------------------
1 | import { Prototype } from "./prototype";
2 |
3 | export class ConcretePrototype2 implements Prototype {
4 | operation() {
5 | console.log("Operation from ConcretePrototype2");
6 | }
7 |
8 | clone(): Prototype {
9 | return new ConcretePrototype2();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/prototype-pattern/example1/concrete.prototype1.ts:
--------------------------------------------------------------------------------
1 | import { Prototype } from "./prototype";
2 |
3 | export class ConcretePrototype1 implements Prototype {
4 | operation() {
5 | console.log("Operation from ConcretePrototype1");
6 | }
7 |
8 | clone(): Prototype {
9 | return new ConcretePrototype1();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/state-pattern/example1/state-solution-1/state.ts:
--------------------------------------------------------------------------------
1 | import { Context } from "./context";
2 |
3 | export abstract class State {
4 | protected context: Context;
5 |
6 | public setContext(context: Context) {
7 | this.context = context;
8 | }
9 |
10 | public abstract handle1(): void;
11 | public abstract handle2(): void;
12 | }
--------------------------------------------------------------------------------
/adapter-pattern/example2/models/human-adapter.model.ts:
--------------------------------------------------------------------------------
1 | import { PureRace } from '../interfaces/pure-race.interface';
2 | import { Human } from './human.model';
3 |
4 | export class HumanAdapter implements PureRace {
5 | constructor(private human: Human) {}
6 |
7 | public genki(): number {
8 | return this.human.sharedPower();
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/facade-pattern/example2/problem/pokemon/fighting-pokemon.model.ts:
--------------------------------------------------------------------------------
1 | import { Pokemon } from './pokemon.model';
2 |
3 | export class FightingPokemon extends Pokemon {
4 | constructor(_pokemon) {
5 | super(_pokemon);
6 | }
7 | calculateImpact(multipliers) {
8 | return Math.floor((this.attack / this.defense) * multipliers) + 1;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/facade-pattern/example2/problem/pokemon/ground-pokemon.model.ts:
--------------------------------------------------------------------------------
1 | import { Pokemon } from './pokemon.model';
2 |
3 | export class GroundPokemon extends Pokemon {
4 | constructor(_pokemon) {
5 | super(_pokemon);
6 | }
7 | calculateImpact(multipliers) {
8 | return Math.floor((this.attack + this.defense) * multipliers) + 1;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/facade-pattern/example2/problem/pokemon/poison-pokemon.model.ts:
--------------------------------------------------------------------------------
1 | import { Pokemon } from './pokemon.model';
2 |
3 | export class PoisonPokemon extends Pokemon {
4 | constructor(_pokemon) {
5 | super(_pokemon);
6 | }
7 | calculateImpact(multipliers) {
8 | return Math.floor((this.attack - this.defense) * multipliers) + 1;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/factory-method-pattern/example1/concrete-creator1.ts:
--------------------------------------------------------------------------------
1 | import { ConcreteProduct1 } from "./concrete-product1";
2 | import { Creator } from "./creator";
3 | import { Product } from "./product.interface";
4 |
5 | export class ConcreteCreator1 extends Creator {
6 | protected factoryMethod(): Product {
7 | return new ConcreteProduct1();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/factory-method-pattern/example1/concrete-creator2.ts:
--------------------------------------------------------------------------------
1 | import { ConcreteProduct2 } from "./concrete-product2";
2 | import { Creator } from "./creator";
3 | import { Product } from "./product.interface";
4 |
5 | export class ConcreteCreator2 extends Creator {
6 | protected factoryMethod(): Product {
7 | return new ConcreteProduct2();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/observer-pattern/example2/product.model.ts:
--------------------------------------------------------------------------------
1 | import { Auctioneer } from "./auctioneer.interface";
2 |
3 | export class Product {
4 | public price;
5 | public name;
6 | public auctionner: Auctioneer = null;
7 |
8 | constructor(product) {
9 | this.price = product.price || 10;
10 | this.name = product.name || "Unknown";
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/adapter-pattern/example2/models/namekian-adapter.model.ts:
--------------------------------------------------------------------------------
1 | import { PureRace } from '../interfaces/pure-race.interface';
2 | import { Namekian } from './namekian';
3 |
4 | export class NamekianAdapter implements PureRace {
5 | constructor(private namekian: Namekian) {}
6 | public genki(): number {
7 | return this.namekian.getPower();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/facade-pattern/example2/facade-solution/pokemon/ground-pokemon.model.ts:
--------------------------------------------------------------------------------
1 | import { Pokemon } from './pokemon.model';
2 |
3 | export class GroundPokemon extends Pokemon {
4 | constructor(_pokemon) {
5 | super(_pokemon);
6 | }
7 | calculateImpact(multipliers) {
8 | return Math.floor((this.attack + this.defense) * multipliers) + 1;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/facade-pattern/example2/facade-solution/pokemon/poison-pokemon.model.ts:
--------------------------------------------------------------------------------
1 | import { Pokemon } from './pokemon.model';
2 |
3 | export class PoisonPokemon extends Pokemon {
4 | constructor(_pokemon) {
5 | super(_pokemon);
6 | }
7 | calculateImpact(multipliers) {
8 | return Math.floor((this.attack - this.defense) * multipliers) + 1;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/bridge-pattern/example2/problem/desktop-messaging.ts:
--------------------------------------------------------------------------------
1 | // DesktopMessaging.ts
2 | export class DesktopMessaging {
3 | sendMessageFromDesktop(message: string): void {
4 | console.log("Sending message from a desktop: " + message);
5 | }
6 |
7 | receiveMessageOnDesktop(): string {
8 | return "Message received on a desktop.";
9 | }
10 | }
--------------------------------------------------------------------------------
/bridge-pattern/example2/solution/advanced-messaging.ts:
--------------------------------------------------------------------------------
1 | import { MessagingService } from './messaging-sender';
2 |
3 | export class AdvancedMessaging extends MessagingService {
4 | send(message: string): void {
5 | this.sender.sendMessage(message);
6 | }
7 |
8 | receive(): string {
9 | return this.sender.receiveMessage();
10 | }
11 | }
--------------------------------------------------------------------------------
/facade-pattern/example2/facade-solution/pokemon/fighting-pokemon.model.ts:
--------------------------------------------------------------------------------
1 | import { Pokemon } from './pokemon.model';
2 |
3 | export class FightingPokemon extends Pokemon {
4 | constructor(_pokemon) {
5 | super(_pokemon);
6 | }
7 | calculateImpact(multipliers) {
8 | return Math.floor((this.attack / this.defense) * multipliers) + 1;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/null-object-pattern/example1/null-object-solution-1/null-saiyan.class.ts:
--------------------------------------------------------------------------------
1 | import { AbstractSaiyan } from './saiyan.class';
2 |
3 | export class NullSaiyan extends AbstractSaiyan {
4 | public getName(): string {
5 | return 'Not Available in Saiyan Database';
6 | }
7 | toString(): string {
8 | return 'Not Available in Saiyan Database';
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/bridge-pattern/example1/refine-abstraction.ts:
--------------------------------------------------------------------------------
1 | // Esta es una versión refinada de la abstracción.
2 | import { Abstraction } from './abstraction';
3 |
4 | export class RefinedAbstraction extends Abstraction {
5 | operation(): void {
6 | console.log('RefinedAbstraction: operation');
7 | this.implementor.operationImplementation();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/chain-responsibility-pattern/example1/handlerA.ts:
--------------------------------------------------------------------------------
1 | import { AbstractHandler } from "./abstract-handler";
2 |
3 | export class HandlerA extends AbstractHandler {
4 | public handle(request: string): string {
5 | if (request === "optionA") {
6 | return `A: I'll do the operation -> ${request}.`;
7 | }
8 | return super.handle(request);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/chain-responsibility-pattern/example1/handlerB.ts:
--------------------------------------------------------------------------------
1 | import { AbstractHandler } from "./abstract-handler";
2 |
3 | export class HandlerB extends AbstractHandler {
4 | public handle(request: string): string {
5 | if (request === "optionB") {
6 | return `B: I'll do the operation -> ${request}.`;
7 | }
8 | return super.handle(request);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/chain-responsibility-pattern/example1/handlerC.ts:
--------------------------------------------------------------------------------
1 | import { AbstractHandler } from "./abstract-handler";
2 |
3 | export class HandlerC extends AbstractHandler {
4 | public handle(request: string): string {
5 | if (request === "optionC") {
6 | return `C: I'll do the operation -> ${request}.`;
7 | }
8 | return super.handle(request);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/facade-pattern/example2/problem/dragonball/models/human-adapter.model.ts:
--------------------------------------------------------------------------------
1 | import { PureRace } from '../interfaces/pure-race.interface';
2 | import { Human } from './human.model';
3 |
4 | export class HumanAdapter implements PureRace {
5 | constructor(private human: Human) {}
6 |
7 | public genki(): number {
8 | return this.human.sharedPower();
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/composite-pattern/example2/problem/ingredient.ts:
--------------------------------------------------------------------------------
1 | export class Ingredient {
2 | name: string;
3 | amount: string;
4 |
5 | constructor(name: string, amount: string) {
6 | this.name = name;
7 | this.amount = amount;
8 | }
9 |
10 | showDetails(): string {
11 | return `Ingredient: ${this.name}, Amount: ${this.amount}`;
12 | }
13 | }
--------------------------------------------------------------------------------
/bridge-pattern/example2/solution/messaging-sender.ts:
--------------------------------------------------------------------------------
1 | import { MessageSender } from './message-sender';
2 |
3 | export abstract class MessagingService {
4 | protected sender: MessageSender;
5 |
6 | constructor(sender: MessageSender) {
7 | this.sender = sender;
8 | }
9 |
10 | abstract send(message: string): void;
11 | abstract receive(): string;
12 | }
--------------------------------------------------------------------------------
/facade-pattern/example2/facade-solution/dragonball/models/human-adapter.model.ts:
--------------------------------------------------------------------------------
1 | import { PureRace } from '../interfaces/pure-race.interface';
2 | import { Human } from './human.model';
3 |
4 | export class HumanAdapter implements PureRace {
5 | constructor(private human: Human) {}
6 |
7 | public genki(): number {
8 | return this.human.sharedPower();
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/facade-pattern/example2/problem/dragonball/models/namekian-adapter.model.ts:
--------------------------------------------------------------------------------
1 | import { PureRace } from '../interfaces/pure-race.interface';
2 | import { Namekian } from './namekian';
3 |
4 | export class NamekianAdapter implements PureRace {
5 | constructor(private namekian: Namekian) {}
6 | public genki(): number {
7 | return this.namekian.getPower();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/adapter-pattern/example2/models/saiyan-adapter.model.ts:
--------------------------------------------------------------------------------
1 | import { PureRace } from '../interfaces/pure-race.interface';
2 | import { Saiyan } from './saiyan.model';
3 |
4 | export class SaiyanAdapter implements PureRace {
5 | constructor(private saiyan: Saiyan) {}
6 | public genki(): number {
7 | return this.saiyan.myPowerPart1() + this.saiyan.myPowerPart2();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/bridge-pattern/example1/abstraction.ts:
--------------------------------------------------------------------------------
1 | // Esta es la abstracción en el patrón Bridge.
2 | import { Implementor } from './implementor';
3 |
4 | export abstract class Abstraction {
5 | protected implementor: Implementor;
6 |
7 | constructor(implementor: Implementor) {
8 | this.implementor = implementor;
9 | }
10 |
11 | abstract operation(): void;
12 | }
13 |
--------------------------------------------------------------------------------
/bridge-pattern/example2/problem/mobile-messaging.ts:
--------------------------------------------------------------------------------
1 | // MobileMessaging.ts
2 | export class MobileMessaging {
3 | sendMessageFromMobile(message: string): void {
4 | console.log("Sending message from a mobile device: " + message);
5 | }
6 |
7 | receiveMessageOnMobile(): string {
8 | return "Message received on a mobile device.";
9 | }
10 | }
11 |
12 |
13 |
--------------------------------------------------------------------------------
/facade-pattern/example1/facade-solution-1/index.ts:
--------------------------------------------------------------------------------
1 | import { Facade } from './facade';
2 |
3 | class Client {
4 | facade = new Facade();
5 | methodClient1() {
6 | this.facade.methodClient1();
7 | }
8 |
9 | methodClient2() {
10 | this.facade.methodClient2();
11 | }
12 | }
13 |
14 | const client = new Client();
15 | client.methodClient1();
16 | client.methodClient2();
17 |
--------------------------------------------------------------------------------
/facade-pattern/example1/facade-solution-2/index.ts:
--------------------------------------------------------------------------------
1 | import { Facade } from './facade';
2 |
3 | class Client {
4 | facade = new Facade();
5 | methodClient1() {
6 | this.facade.methodClient1();
7 | }
8 |
9 | methodClient2() {
10 | this.facade.methodClient2();
11 | }
12 | }
13 |
14 | const client = new Client();
15 | client.methodClient1();
16 | client.methodClient2();
17 |
--------------------------------------------------------------------------------
/facade-pattern/example2/facade-solution/dragonball/models/namekian-adapter.model.ts:
--------------------------------------------------------------------------------
1 | import { PureRace } from '../interfaces/pure-race.interface';
2 | import { Namekian } from './namekian.model';
3 |
4 | export class NamekianAdapter implements PureRace {
5 | constructor(private namekian: Namekian) {}
6 | public genki(): number {
7 | return this.namekian.getPower();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/bridge-pattern/example2/solution/desktop-sender.ts:
--------------------------------------------------------------------------------
1 | import { MessageSender } from './message-sender';
2 |
3 | export class DesktopSender implements MessageSender {
4 | sendMessage(message: string): void {
5 | console.log("Sending message from a desktop: " + message);
6 | }
7 |
8 | receiveMessage(): string {
9 | return "Message received on a desktop.";
10 | }
11 | }
--------------------------------------------------------------------------------
/decorator-pattern/example2/decorator-solution/lord-decorator.ts:
--------------------------------------------------------------------------------
1 | import { Character } from './character.interface';
2 | import { WhiteWalkerDecorator } from './white-walker-decorator';
3 |
4 | export class LordDecorator extends WhiteWalkerDecorator {
5 | constructor(character: Character) {
6 | super(character);
7 | character.setLife(1000);
8 | this.power = 3;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/factory-method-pattern/example3/creator.ts:
--------------------------------------------------------------------------------
1 | import { Product } from "./product.interface";
2 |
3 | export abstract class Creator {
4 |
5 | public abstract factoryMethod(): Product;
6 |
7 | public someOperation(): string {
8 | const product = this.factoryMethod();
9 | return `Creator: The same creator's code has just worked with ${product.operation()}`;
10 | }
11 | }
--------------------------------------------------------------------------------
/understanding-this-in-js/09 - exercises/exercise-01.js:
--------------------------------------------------------------------------------
1 | function multiply(p, q, callback) {
2 | callback(p * q);
3 | }
4 |
5 | let user = {
6 | a: 2,
7 | b:3,
8 | findMultiply: function() {
9 | multiply(this.a, this.b, function(total) {
10 | console.log(total);
11 | console.log(this === window);
12 | })
13 | }
14 | }
15 |
16 | user.findMultiply();
17 | //Prints 6
18 | //Prints true
--------------------------------------------------------------------------------
/decorator-pattern/example1/decorator-solution-1/decorator.ts:
--------------------------------------------------------------------------------
1 | import { Component } from './component.interface';
2 |
3 | export class Decorator implements Component {
4 | protected component: Component;
5 |
6 | constructor(component: Component) {
7 | this.component = component;
8 | }
9 |
10 | public operation(): string {
11 | return this.component.operation();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/workshop-javascript/problems/Problem2/main.js:
--------------------------------------------------------------------------------
1 | let randomNumber;
2 | let life;
3 | function start() {
4 | configure();
5 | play();
6 | }
7 | function configure() {
8 | randomNumber = parseInt(Math.random() * 6) + 1;
9 | life = 3;
10 | }
11 | function play() {
12 | /* Para pedir: prompt("Adivina el numero:");*/
13 | /* Para enviar mensaje: alert("Acertado");*/
14 | /* TODO */
15 | }
16 |
--------------------------------------------------------------------------------
/bridge-pattern/example2/solution/mobile-sender.ts:
--------------------------------------------------------------------------------
1 | import { MessageSender } from './message-sender';
2 |
3 | export class MobileSender implements MessageSender {
4 | sendMessage(message: string): void {
5 | console.log("Sending message from a mobile device: " + message);
6 | }
7 |
8 | receiveMessage(): string {
9 | return "Message received on a mobile device.";
10 | }
11 | }
--------------------------------------------------------------------------------
/facade-pattern/example2/problem/dragonball/models/saiyan-adapter.model.ts:
--------------------------------------------------------------------------------
1 | import { PureRace } from '../interfaces/pure-race.interface';
2 | import { Saiyan } from './saiyan.model';
3 |
4 | export class SaiyanAdapter implements PureRace {
5 | constructor(private saiyan: Saiyan) {}
6 | public genki(): number {
7 | return this.saiyan.myPowerPart1() + this.saiyan.myPowerPart2();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/facade-pattern/example2/facade-solution/dragonball/models/saiyan-adapter.model.ts:
--------------------------------------------------------------------------------
1 | import { PureRace } from '../interfaces/pure-race.interface';
2 | import { Saiyan } from './saiyan.model';
3 |
4 | export class SaiyanAdapter implements PureRace {
5 | constructor(private saiyan: Saiyan) {}
6 | public genki(): number {
7 | return this.saiyan.myPowerPart1() + this.saiyan.myPowerPart2();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/proxy-pattern/example2/proxies/lazy.proxy.ts:
--------------------------------------------------------------------------------
1 | import { RealSubject, Subject } from "../subjects/";
2 |
3 | export class LazyProxy implements Subject {
4 | private realSubject: RealSubject | null = null;
5 |
6 | operation(): void {
7 | if (this.realSubject === null) {
8 | this.realSubject = new RealSubject();
9 | }
10 | this.realSubject.operation();
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/singleton-pattern/example1/problem/index.ts:
--------------------------------------------------------------------------------
1 | import { Client1 } from './client1';
2 | import { Client2 } from './client2';
3 |
4 | const client1 = new Client1();
5 | console.log(
6 | 'DatabaseConnection ID:',
7 | client1.getUniqueIdentificatorConnection()
8 | );
9 |
10 | const client2 = new Client2();
11 | console.log(
12 | 'DatabaseConnection ID:',
13 | client2.getUniqueIdentificatorConnection()
14 | );
15 |
--------------------------------------------------------------------------------
/singleton-pattern/example2/problem/index.ts:
--------------------------------------------------------------------------------
1 | import { Client1 } from './client1';
2 | import { Client2 } from './client2';
3 |
4 | const client1 = new Client1();
5 | console.log(
6 | 'DatabaseConnection ID:',
7 | client1.getUniqueIdentificatorConnection()
8 | );
9 |
10 | const client2 = new Client2();
11 | console.log(
12 | 'DatabaseConnection ID:',
13 | client2.getUniqueIdentificatorConnection()
14 | );
15 |
--------------------------------------------------------------------------------
/adapter-pattern/example1/models/android-adapter.model.ts:
--------------------------------------------------------------------------------
1 | import { Warrior } from '../interfaces/warrior.interface';
2 | import { Android } from './android.model';
3 |
4 | export class AndroidAdapter implements Warrior {
5 | constructor(private android: Android) {}
6 | public ATTACK_BASE = 50;
7 | public attack(): number {
8 | return this.android.kick() + this.android.punch() + this.ATTACK_BASE;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/understanding-this-in-js/03-keyword-new/new-02.js:
--------------------------------------------------------------------------------
1 | function Dog(name, job) {
2 | this.name = name;
3 | this.job = job;
4 |
5 | this.displayName = function () {
6 | console.log(`this is in the Dog context:: ${this.name} ${this.job}`);
7 | }
8 | }
9 |
10 | const turbot = new Dog('Turbot', 'Police');
11 | const rubble = new Dog('Rubble', 'Worker');
12 | turbot.displayName();
13 | rubble.displayName();
--------------------------------------------------------------------------------
/mediator-pattern/example1/colleague1.ts:
--------------------------------------------------------------------------------
1 | import { Colleague } from "./colleague";
2 | import { Mediator } from "./mediator";
3 |
4 | export class Colleague1 implements Colleague {
5 | private mediator: Mediator;
6 |
7 | setMediator(mediator: Mediator): void {
8 | this.mediator = mediator;
9 | }
10 |
11 | action(): void {
12 | this.mediator.notify(this, "Event from Colleague1");
13 | }
14 | }
--------------------------------------------------------------------------------
/mediator-pattern/example1/colleague2.ts:
--------------------------------------------------------------------------------
1 | import { Colleague } from "./colleague";
2 | import { Mediator } from "./mediator";
3 |
4 | export class Colleague2 implements Colleague {
5 | private mediator: Mediator;
6 |
7 | setMediator(mediator: Mediator): void {
8 | this.mediator = mediator;
9 | }
10 |
11 | action(): void {
12 | this.mediator.notify(this, "Event from Colleague2");
13 | }
14 | }
--------------------------------------------------------------------------------
/singleton-pattern/example1/singleton-solution-1/index.ts:
--------------------------------------------------------------------------------
1 | import { Client1 } from './client1';
2 | import { Client2 } from './client2';
3 |
4 | const client1 = new Client1();
5 | console.log(
6 | 'DatabaseConnection ID:',
7 | client1.getUniqueIdentificatorConnection()
8 | );
9 |
10 | const client2 = new Client2();
11 | console.log(
12 | 'DatabaseConnection ID:',
13 | client2.getUniqueIdentificatorConnection()
14 | );
15 |
--------------------------------------------------------------------------------
/demeter/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "demeter-law",
3 | "version": "0.0.1",
4 | "description": "",
5 | "scripts": {
6 | "example1": "nodemon --config nodemon-example1.json"
7 | },
8 | "keywords": [
9 | "demeter-law",
10 | "clean-code"
11 | ],
12 | "author": "Carlos Caballero",
13 | "license": "MIT",
14 | "devDependencies": {
15 | "typescript": "^3.3.3333",
16 | "nodemon": "^1.18.10"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/iterators-javascript/example2/iterator-solution/social-network.interface.ts:
--------------------------------------------------------------------------------
1 | import { Profile } from './profile.class';
2 | import { ProfileIterator } from './profile-iterator.interface';
3 |
4 | export interface SocialNetwork {
5 | createFriendsIterator(profileEmail: string): ProfileIterator;
6 | createCoworkersIterator(profileEmail: string): ProfileIterator;
7 | createNativeIterator(type: string, profileEmail: string): Iterable;
8 | }
9 |
--------------------------------------------------------------------------------
/understanding-this-in-js/03-keyword-new/new-03.js:
--------------------------------------------------------------------------------
1 | /* Using prototype */
2 | function Dog(name, job) {
3 | this.name = name;
4 | this.job = job;
5 | }
6 | Dog.prototype.displayName = function () {
7 | console.log(`this is in the Dog context:: ${this.name} ${this.job}`);
8 | }
9 |
10 | const turbot = new Dog('Turbot', 'Police');
11 | const rubble = new Dog('Rubble', 'Worker');
12 | turbot.displayName();
13 | rubble.displayName();
14 |
--------------------------------------------------------------------------------
/command-pattern/example2/command-solution-1/commands/clean-command.ts:
--------------------------------------------------------------------------------
1 | import { Command } from './command.class';
2 | import { R2D2Service } from '../services';
3 |
4 | export class CleanCommand extends Command {
5 | public constructor(private r2d2Service: R2D2Service) {
6 | super();
7 | }
8 | public execute(): void {
9 | console.log('Execute -> Clean Command');
10 | this.r2d2Service.clean();
11 | console.log();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/state-pattern/example2/problem/index.ts:
--------------------------------------------------------------------------------
1 | import { Freeza } from "./freeza";
2 | import { State } from "./state.enum";
3 |
4 | const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
5 | const freeza = new Freeza(State.TRANSFORMATION1); // Initial State
6 |
7 | (async () => {
8 | while(freeza.isAlive()){
9 | freeza.attack();
10 | await sleep(1000);
11 | freeza.defend(10);
12 | await sleep(1000);
13 | }
14 | })();
15 |
--------------------------------------------------------------------------------
/command-pattern/example1/command-solution-1/agent.class.ts:
--------------------------------------------------------------------------------
1 | import { Order } from './order.class';
2 |
3 | // Invoker.
4 | export class Agent {
5 | private orders: Order[] = [];
6 |
7 | public constructor() {}
8 |
9 | placeOrder(order: Order) {
10 | this.orders.push(order);
11 | order.execute();
12 | }
13 |
14 | listOrders(): string {
15 | return this.orders.reduce((acc, curr) => acc + curr.toString() + '\n', '');
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/iterator-pattern/example1/problem/example1.puml:
--------------------------------------------------------------------------------
1 | @startuml
2 | class Client {}
3 | class WordsCollection {
4 | -items: string[] = []
5 |
6 | +getItems(): string[]
7 | +addItem(item: string): void
8 | }
9 |
10 | Client .> WordsCollection : "<