...
/Solution: Create a Feature-Flagged Analytics Service
Solution: Create a Feature-Flagged Analytics Service
Use a flag-to-class map to instantiate the correct service: real or stub; without any conditionals.
We'll cover the following...
We'll cover the following...
Solution explanation
Lines 1–16: We define two interchangeable service classes:
AnalyticsServiceandStubService.AnalyticsServicelogs events and generates reports when analytics is enabled.StubServiceprovides empty.track()and.report()methods so calls remain safe even when analytics is disabled.
Lines 18–21: The
serviceMapobject maps theanalyticsEnabled...