Tier 4
Series 302
302D: The Service Dock
"Singletons are useful, but "Hard Singletons" act like super-glue. If your Player script calls `Audio.Instance.Play()`, you can never test the Player without the Audio system present. A Navigator uses a Service Locator to allow systems to connect without welding themselves together."
The Concept: Service Locator
The **Service Locator** is a registry where systems allow themselves to be found. It acts as a middleman.
* **Registration:** `ServiceLocator.Register(new AudioManager());`
* **Retrieval:** `var audio = ServiceLocator.Get();`
* **Benefit:** You can swap the "Real Audio" for "Dummy Audio" during testing.
* **Registration:** `ServiceLocator.Register
* **Retrieval:** `var audio = ServiceLocator.Get
* **Benefit:** You can swap the "Real Audio" for "Dummy Audio" during testing.
Red Flag Detected
The AI Trap: "The Hard Dependency"
You ask the AI: "Play a sound when the player jumps."
// AI-Generated Code: Tightly Coupled
void Jump() {
// Audit Fail: Hard dependency on a specific static class.
// If AudioManager is missing, the Player script crashes.
AudioManager.Instance.PlayJump();
}
This is "Architecture Rigidity." You cannot unit test this Jump function in isolation because it demands the entire Audio system be loaded.
Elite Telemetry
Research shows "Elite" teams achieve 15% faster lead times by keeping AI on a "very tight leash."
- Small Batches Solving one problem at a time prevents logic drift.
- Modular Design Localizing the "blast radius" of AI changes.
- Tight Loops Rapid iteration with constant code review.
The Navigator's Correction
Corrective Protocol
// Corrected: Decoupled & Testable
void Jump() {
// We ask for "An Audio Service", we don't care which one.
ServiceLocator.Get<IAudioService>().Play("Jump");
}
Your Pilot Command
> A skilled Navigator directs the AI to use Service Location.