Skip to content

Instantly share code, notes, and snippets.

@DylanSp
Created July 23, 2019 12:03
Show Gist options
  • Save DylanSp/1e36adf70173a626f3e496439a7ed29c to your computer and use it in GitHub Desktop.
Save DylanSp/1e36adf70173a626f3e496439a7ed29c to your computer and use it in GitHub Desktop.
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