Skip to main content

Practice ยท 2 of 4

Decorator: Stack Behaviors on a Client

CHALLENGE
Difficulty: intermediate+25 XP

IApiClient.Send(string path) returns "200:" + path. Build a **Decorator** stack around it โ€” each decorator wraps exactly one IApiClient and adds one behavior: - Caching โ€” returns the inner response without calling inner again for a path it has already served (expose InnerCalls count). - Uppercase โ€” transforms the response to upper-case (applies after inner, so caching stores the original and uppercasing runs every call). Solution.Run() builds new Uppercase(new Caching(new Base())) and issues "a", "a", "b" โ€” then the tests verify the call counts and outputs. ``csharp public static class Solution { public interface IApiClient { string Send(string path); } public sealed class Caching : IApiClient { public int InnerCalls; /* wraps one IApiClient */ } public sealed class Uppercase : IApiClient { /* wraps one IApiClient */ } public static string[] Run(); } ``

Back to lesson: Practice: Patterns Practice: Strategy, Decorator, Builder