Search⌘ K
AI Features

Solution: Add Feature-Flagged Logger Instantiation

Explore applying the factory design pattern to dynamically create logger instances driven by runtime feature flags. Understand how to map feature flags to interchangeable logger classes and centralize creation logic to enable flexible and maintainable Node.js services.

Solution explanation

  • Lines 1–11: We define two interchangeable logger classes: FileLogger and RemoteLogger.

    • Both implement a .log() method, ensuring consistent behavior for consumers regardless of which one is used.

    • FileLogger simulates local file logging, while RemoteLogger represents a new network-based logging service.

  • ...