Created
January 16, 2018 18:33
-
-
Save porfidev/0925f2df7d34489b7197ac2f33961eea to your computer and use it in GitHub Desktop.
Fábrica Abstracta para Typescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { CallOfDutyCover, CallOfDutyDisc} from "./product_classes"; | |
/** | |
* Game Factory Classes | |
*/ | |
export abstract class AbstractGameFactory { | |
abstract makeDisc(); | |
abstract makeCover(); | |
} | |
export class PS4GameFactory extends AbstractGameFactory { | |
private brand = 'Sony'; | |
makeDisc() { | |
return new CallOfDutyDisc(); | |
} | |
makeCover() { | |
return new CallOfDutyCover(); | |
} | |
} | |
export class XBOXGameFactory extends AbstractGameFactory { | |
private brand = 'Microsoft'; | |
makeDisc() { | |
return new CallOfDutyDisc; | |
} | |
makeCover() { | |
return new CallOfDutyCover; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {PS4GameFactory, XBOXGameFactory} from "./factory_clases"; | |
export class GameMaker { | |
public constructor() { | |
const ps4Game = new PS4GameFactory(); | |
this.tester(ps4Game); | |
const xboxGame = new XBOXGameFactory(); | |
this.tester(xboxGame); | |
} | |
tester(game) { | |
const cover = game.makeCover(); | |
const disc = game.makeDisc(); | |
console.log('=============='); | |
console.log(cover.getPaperType()); | |
console.log(cover.getSize()); | |
console.log(disc.getGenre()); | |
console.log(disc.getTitle()); | |
console.log('=============='); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Game Products Classes | |
*/ | |
export abstract class AbstractDisc { | |
abstract getTitle(); | |
abstract getGenre(); | |
} | |
export abstract class AbstractCover { | |
abstract getSize(); | |
abstract getPaperType(); | |
} | |
abstract class AbstractCallOfDuty { | |
private gameSeries = 'Call of Duty'; | |
getGameSeries() { | |
return this.gameSeries; | |
} | |
} | |
export class CallOfDutyDisc extends AbstractCallOfDuty implements AbstractDisc { | |
private title = 'Modern Warfare'; | |
private genre = 'FPS'; | |
getTitle() { | |
return this.title; | |
} | |
getGenre() { | |
return this.genre; | |
} | |
} | |
export class CallOfDutyCover extends AbstractCallOfDuty implements AbstractCover { | |
private size = '4x6'; | |
private paperType = 'couche'; | |
getSize() { | |
return this.size; | |
} | |
getPaperType() { | |
return this.paperType; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment