Created
July 23, 2019 12:03
-
-
Save DylanSp/1e36adf70173a626f3e496439a7ed29c to your computer and use it in GitHub Desktop.
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 ILogger { | |
log: (str: string) => void; | |
} | |
class Logger implements ILogger { | |
log = (str: string): void => { | |
console.log(str); | |
}; | |
} | |
class MyBusinessClass { | |
constructor(private logger: Logger) {} | |
addEffectful = (a: number, b: number): number => { | |
this.logger.log(a.toString()); | |
this.logger.log(b.toString()); | |
return a + b; | |
}; | |
} | |
const logger = new Logger(); | |
const business = new MyBusinessClass(logger); | |
const result = business.addEffectful(1, 2); | |
console.log(`result: ${result}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment