This file contains hidden or 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
abstract class Pie { | |
protected addFlour(): void { | |
console.log("Pie: addFlour"); | |
} | |
protected addEggs(): void { | |
console.log("Pie: addEggs"); | |
} | |
protected addWater(): void { |
This file contains hidden or 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
interface Strategy { | |
execute(): void; | |
} | |
class ExploreTheWorldStrategy implements Strategy { | |
public execute(): void { | |
console.log("ExploreTheWorldStrategy executed!"); | |
} | |
} |
This file contains hidden or 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
const coffeeMachine: CoffeeMachine = new CoffeeMachine(new CoffeeMachineReadyState()); | |
coffeeMachine.request(); | |
coffeeMachine.request(); | |
coffeeMachine.request(); | |
coffeeMachine.request(); | |
coffeeMachine.request(); | |
coffeeMachine.request(); | |
coffeeMachine.fillWaterTank(50); | |
coffeeMachine.request(); | |
coffeeMachine.request(); |
This file contains hidden or 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
interface State { | |
handle(machine: CoffeeMachine): void; | |
} | |
class CoffeeMachineReadyState implements State { | |
public handle(machine: CoffeeMachine): void { | |
console.log("CoffeeMachineReadyState: ready to work!"); | |
if (machine.isWaterTankEmpty()) { | |
machine.State = new WaterTankEmptyState(); | |
return; |
This file contains hidden or 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
class ClipboardState { | |
private copiedContent: string; | |
constructor(command: string) { | |
this.copiedContent = command; | |
} | |
get Command(): string { | |
return this.copiedContent; | |
} |
This file contains hidden or 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
interface Mediator { | |
notify(sender: object, message: string): void; | |
} | |
class Car { | |
protected mediator: Mediator; | |
public setMediator(mediator: Mediator): void { | |
this.mediator = mediator; | |
} |
This file contains hidden or 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
const cakes = [ | |
"New York Cheesecake", | |
"Molten Chocolate Cake", | |
"Tres Leches Cake", | |
"Schwarzwälder Kirschtorte", | |
"Cremeschnitte", | |
"Sachertorte", | |
"Kasutera", | |
]; | |
const cakeRecipes: CakeRecipes = new CakeRecipes(cakes); |
This file contains hidden or 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
interface RecipeIterator { | |
next(): any; | |
hasNext(): boolean; | |
} | |
interface RecipeAggregator { | |
createIterator(): RecipeIterator; | |
} | |
class CakeRecipeIterator implements RecipeIterator { |
This file contains hidden or 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
const videoGame: VideoGame = new VideoGame(); | |
const openInventoryKeyboardCommand: Command = new OpenInventoryKeyboardCommand(videoGame); | |
const openInventoryButtonCommand: Command = new OpenInventoryButtonCommand(videoGame); | |
const operatingSystem: OperatingSystem = new OperatingSystem(); | |
operatingSystem.storeAndExecute(openInventoryKeyboardCommand); | |
operatingSystem.storeAndExecute(openInventoryButtonCommand); | |
/* | |
"KeyboardShortcutCommand: execute method called!" | |
"VideoGame: action is being executed!" |
This file contains hidden or 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
interface Command { | |
execute(): void; | |
} | |
class OpenInventoryKeyboardCommand implements Command { | |
private videoGame: VideoGame; | |
constructor(videoGame: VideoGame) { | |
this.videoGame = videoGame; | |
} |