forked from Sean-Bradley/Design-Patterns-In-TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleopard.ts
More file actions
26 lines (22 loc) · 814 Bytes
/
Copy pathleopard.ts
File metadata and controls
26 lines (22 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import IProteus from './iproteus'
import Lion from './lion'
import Serpent from './serpent'
export default class Leopard implements IProteus {
// Proteus in the form of a Leopard
name = 'Leopard'
tellMeTheFuture(): void {
// Proteus will change to something random
if (Math.floor(Math.random() * 2)) {
Object.assign(this, new Lion())
this.tellMeTheFuture = Lion.prototype.tellMeTheFuture
this.tellMeYourForm = Lion.prototype.tellMeYourForm
} else {
Object.assign(this, new Serpent())
this.tellMeTheFuture = Serpent.prototype.tellMeTheFuture
this.tellMeYourForm = Serpent.prototype.tellMeYourForm
}
}
tellMeYourForm(): void {
console.log(`I am the form of ${this.name}`)
}
}