Created
January 9, 2020 18:10
-
-
Save omarkdev/93f26cbc7564152675259b8e87152af2 to your computer and use it in GitHub Desktop.
Exemplo ANTES 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
interface Logger { | |
warn(message: string): void; | |
} | |
class ConsoleLogger implements Logger { | |
warn(message: string): void { | |
console.warn(message); | |
} | |
} | |
class LoggerFactory { | |
factory(env: string): Logger | null { | |
if (env === 'development') { | |
return new ConsoleLogger(); | |
} | |
return null; | |
} | |
} | |
class Client { | |
execute() { | |
const logger = (new LoggerFactory()).factory('production'); | |
if (logger !== null) { | |
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