Last active
January 9, 2020 18:20
-
-
Save omarkdev/89d4d7d86f4583f62bc9d3d290067e15 to your computer and use it in GitHub Desktop.
Exemplo DEPOIS da refatoração do artigo Design Patterns: Null Object.
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 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