Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Checkpoint โ€” The Generic Data Store

โญโญ intermediateโณ 22 min read๐Ÿ“ Lesson 103 of 265

Build a constrained generic store with ordering, defaults, and variance-safe surfaces.

The gate (mini-build)

A DataStore<TId, TEntity> where TEntity : Entity<TId> and TId : IComparable<TId>:

  • Add(TEntity) / Get(TId) (null when missing) / Delete(TId) (bool).
  • AllOrdered() returns entities ordered by Id โ€” the constraint makes the ordering possible without casts.
  • FirstMatching(Predicate<TEntity>) returns TEntity? (default when none).

Supporting type: public abstract class Entity<TId> { public abstract TId Id { get; } }. The graded test drives two different entity types through one store type โ€” the whole point of generic design.