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 { | |
| insertQuarter(): any; | |
| ejectQuarter(): any; | |
| turnCrank(): any; | |
| dispense(): any; | |
| } | |
| class SoldState implements State { | |
| gumBallMachine: GumBallMachine; |
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 Iterator { | |
| next(): Object; | |
| hasNext(): boolean; | |
| } | |
| class DinnerMenuIterator implements Iterator { | |
| items: MenuItem[]; | |
| position: number = 0; | |
| constructor(items: MenuItem[]) { |
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 CaffeineBeverage { | |
| final prepareRecipe(): void { | |
| this.boilWater(); | |
| this.brew(); | |
| this.pourinCup(); | |
| if (this.customerWantsCondiments()) { | |
| this.addCondiments(); | |
| } | |
| } |
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 Amplifier { | |
| tunner: Tunner; | |
| dvdPlayer: DvdPlayer; | |
| cdPlayer: CdPlayer; | |
| constructor(tunner: Tunner, dvd: DvdPlayer, cd: CdPlayer) { | |
| this.tunner = tunner; | |
| this.dvdPlayer = dvd; | |
| this.cdPlayer = cd; | |
| } |
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 Duck { | |
| quack(): void; | |
| fly(): void; | |
| } | |
| interface Turkey { | |
| gobble(): void; | |
| fly(): 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 Command { | |
| execute(): void; | |
| undo(): void; | |
| } | |
| class Light { | |
| room: string; | |
| constructor(room: string) { | |
| this.room = room; |
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 Beverage { | |
| description: string = "Unknown beverage"; | |
| getDescription() { | |
| return this.description; | |
| } | |
| cost(): number { | |
| return 0; | |
| } |
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 QuackBehavior { | |
| quack(): void; | |
| } | |
| interface FlyBehavior { | |
| fly(): void; | |
| } | |
| class Quack implements QuackBehavior { | |
| quack(): 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
| class Pizza { | |
| bake() {} | |
| prepare() {} | |
| box() {} | |
| cut() {} | |
| } | |
| class CheesePizza extends Pizza {} | |
| class PepperoniPizza extends Pizza {} |
NewerOlder