C# SOLID principles exercises that grade the design
Refactor working C# until the code is easier to change for a reason you can prove. Behavior
tests protect the feature while 244 executable rules grade abstractions,
immutability, interfaces, dependencies, and pattern structure across 28
focused exercises.
All exercises are available on every plan. No project setup or local SDK.
A Run on Ask for the Interface with the field retyped to IMessenger: the samples pass, and the rule against referencing SmtpEmailer still fails.
design exercises
28
executable rules
244
design exercises on the Free plan
28
Beyond naming the acronym
Make the principle survive a workaround
Reading that high-level code should depend on abstractions is easy. The useful judgment is
recognizing when an interface still leaks a vendor DTO, a class accepts the interface but
constructs the concrete anyway, or a service locator merely moves behind a readonly field.
Each kata starts with working code and one plausible design failure. You refactor several
files, keep 122 catalog behavior tests green, and satisfy authored
rules that inspect the submitted type structure. A cosmetic rename cannot clear a dependency
rule.
PaymentImporter reads bank-statement lines, decides duplicates against its own dictionary, and words the summary, so a new statement column, a move to a database, and new finance wording all edit the same method. Split it along those reasons to change, and let the store decide what counts as a duplicate at the moment it stores a payment.
A price calculator switches on a plan-name string and news up each concrete strategy by hand. Extracting an IPricingStrategy looks like the fix, but a tempting in-class factory keeps the concretes wired into the calculator. Make the calculator depend only on the abstraction and let the composition root choose the plan.
An abstract Membership promises renewal even though lifetime memberships cannot renew, forcing RenewalService to recognize a concrete subtype before it can safely use the base contract. Split shared membership identity from the renewable capability, remove the lying inheritance, and make the service depend only on what it can honestly call.
One fat IMachine interface forces the inkjet printer to fake a Scan it cannot perform, and the print queue to demand a scanner it never uses. Split the roles into IPrinter and IScanner. Keeping IMachine around as a composed sub-interface leaves the inkjet transitively welded to scanning and two rules red.
An order notifier news up its own SmtpEmailer and types the field as the concrete class, even though an IMessenger abstraction sits right next to it. Make the notifier ask for the interface in its constructor. Typing the field as IMessenger while still newing the concrete inside is not the fix.
Four object-design skill families
Practice the pressure that makes each principle useful
The exercises are organized by the design decision they force, not by flashcard letters.
That keeps Result models, honest capability contracts, Observer, Strategy, Decorator, value
objects, and SOLID principles attached to the problems they actually solve.
Encapsulation, explicit outcomes, and invariants
9 exercises
Make state ownership, resource lifetimes, and expected outcomes explicit, close mutation leaks, keep snapshots opaque, and encode invariants in types instead of relying on callers to behave.
Single responsibility, dependency inversion, and clean ports
6 exercises
Split a class along its reasons to change, depend on abstractions owned by the policy side, remove the ones nothing varies behind, expose hidden dependencies, and keep vendor types outside application-facing contracts.
Substitutability, interface segregation, and low coupling
4 exercises
Keep subtype contracts honest, shrink roles to what each consumer actually needs, separate queries from commands, and replace long object-navigation chains with intention-revealing boundaries.
Composition and behavioral patterns
9 exercises
Use observers, policies, strategies, null objects, decorators, composites, state objects, undoable commands, and visitors where fixed collaborators, inheritance, switches, type tests, nullable branches, boolean flags, and tagged trees resist change.
28 free C# SOLID and design-pattern exercises
Refactor every design in the browser
Start with one concrete dependency or train wreck, then move into explicit outcomes, honest
subtype contracts, value objects, composition, Observer, Strategy, Null Object, and Decorator.
Every card opens the actual kata.
9 focused refactors
Encapsulation, explicit outcomes, and invariants
Medium4 tests + 10 rules
History Keeps a Checkpoint, Not Editor Internals
Give history immutable checkpoints it can restore repeatedly without seeing the editor's internals.
Preserve the feature, change the reason it is easy to extend
1
Find the design pressure
Read working C# with one specific rigidity: a concrete dependency, fat interface, mutation leak, switch, flag, or global hiding the real seam.
2
Refactor the shape
Edit the multi-file project in the browser. Introduce the smallest abstraction, policy, wrapper, or invariant boundary that resolves the pressure.
3
Prove behavior and design
Submit against behavior tests and executable structural rules. The feature must still work, and the dependency or type shape must genuinely change.
The structural verdict is separate from correctness. Read
how Katabench grades design rules and why a
compiling implementation can still be the wrong shape.
C# SOLID principles exercise FAQ
Before you move the first dependency
What are C# SOLID principles exercises?
+
They are small working C# systems with one design pressure already present. Instead of answering a quiz about an acronym, you refactor the code and receive separate verdicts for preserved behavior and structural design rules such as abstraction use, interface segregation, immutability, sealing, and dependency direction.
Do these exercises cover all five SOLID principles?
+
The strongest direct coverage is Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion, and one exercise splits a class along its reasons to change for Single Responsibility. Related exercises train state ownership, explicit outcomes, composition over inheritance, encapsulation, and value objects. It is a focused practice catalog, not a five-chapter theory course that forces every kata under one letter.
Which C# design patterns can I practice?
+
The catalog includes Strategy, Decorator, Observer, Composite, State, Memento, Command with undo, Visitor, Null Object, Value Object, strongly typed identifiers, one type per lifecycle stage, explicit Result models, command-query separation, composition roots, constructor injection, anti-corruption ports, composition over inheritance, and removing speculative abstractions. Each pattern appears as a response to a concrete design problem rather than an isolated template to copy.
Are all 28 design-principles exercises free?
+
Yes. The complete Design Principles track is currently available on all plans. Daily graded-submission limits still depend on your plan, but none of these exercises is locked behind a specialized-track entitlement.
Do I need Visual Studio or the .NET SDK installed?
+
No. The multi-file editor, compiler, behavior tests, and design-rule grader run from the browser in disposable server-side sandboxes.
How are design-principles exercises different from architecture exercises?
+
Design-principles exercises focus on the internal shape and collaborators of a few types: immutability, interfaces, roles, dependencies, and patterns. Architecture exercises operate at the larger namespace, layer, module, and dependency-graph level.