Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save omarkdev/89d4d7d86f4583f62bc9d3d290067e15 to your computer and use it in GitHub Desktop.
Save omarkdev/89d4d7d86f4583f62bc9d3d290067e15 to your computer and use it in GitHub Desktop.
Exemplo DEPOIS da refatoração do artigo Design Patterns: Null Object.
class NullLogger implements Logger {
warn(message: string): void {
}
}
class LoggerFactory {
factory(env: string): Logger {
if (env === 'development') {
return new ConsoleLogger();
}
return new NullLogger();
}
}
class Client {
execute() {
const logger = (new LoggerFactory()).factory('production');
logger.warn('It\'s on fire, bicho');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment