๐ WAYPOINT LESSON
Checkpoint โ Composite Pipeline
โญโญ intermediateโณ 28 min read๐ Lesson 143 of 265
Compose three patterns into one pipeline: interchangeable validation Strategies, a tolerant pipeline, and a Repository wrapped in an audit Decorator โ with the seams the tests probe.
The gate (mini-build)
One file, three seams, composing patterns you built this module:
- Strategy โ
IRule { string? Check(Solution.Order o); }returning an error message or null. ImplementMinQty(fails when total qty < 2, msg"qty") andPaidSku(fails when any sku is empty, msg"sku"). - Composite/Strategy pipeline โ
Solution.Validate(order, IRule[] rules)returns the first non-null error, or null when all pass. Null rules in the array are skipped (tolerant pipeline). - Repository + audit Decorator โ
IRepo { void Save(Solution.Order o); int Saved; };AuditedRepowraps anyIRepo, counts accepted saves inSaves, and the test flow decides what gets saved.
Flow under test: validate first; save only when valid; AuditedRepo.Saves
must equal the number of valid orders.
public static class Solution
{
public sealed class Order { public string Sku = ""; public int Qty; }
public interface IRule { string? Check(Order o); }
public static string? Validate(Order o, IRule[] rules);
public interface IRepo { void Save(Order o); int Saved { get; } }
public sealed class AuditedRepo : IRepo { public int Saves; /* wraps IRepo */ }
}