Topic
C#
Material specific to C#, or illustrated with C# examples.
16 pages
Writing25 September 2026
Intentional Model Design
A model should express required fields, genuine absence, and distinct variants in its type. Python unions and C# records encode those promises, while boundaries check external values.
Writing17 January 2021
Always Use the "as" Operator? No Thank You!
Use a cast instead of `as` when the type is expected, so a mismatch raises InvalidCastException. Use `is` when the type genuinely varies and keep only guards backed by a real case.
Writing5 December 2020
Separate State from Behavior? Yes Please!
Separating state from behavior simplifies object-oriented systems: immutable DTOs carry data, while managers compose collaborators and make operations explicit at call sites.
Writing25 May 2020
Design Nugget: Evolution To Strategy
Build a working baseline, then change the design for a concrete benefit; a log parser evolves through a switch, delegates, and Strategy to test that judgment.
Writing6 October 2019
Dependency Injection? No Thank You!
Dependency injection exposes private collaborators to callers when used for every internal relationship. Keep classes self-contained and let business code choose real variation.
Writing21 September 2019
Interfaces? No Thank You!
C# interfaces do not inherently create contracts or loose coupling. Composition handles hierarchy conflicts; capability interfaces and structural typing let consumers see only what they need.
Writing20 September 2019
Extension Methods? No Thank You!
Keep project-specific helpers as static methods: extension methods hide behavior behind namespaces and can change meaning with imports. Use them when they serve the wider C# community.
Writing10 September 2019
Factory Pattern: The Enabler of Polymorphism
A Factory selects and constructs a member of a class family from meaningful input, letting clients use the shared contract while the Factory owns recurring implementation choices.
Writing11 August 2019
The Configuration Provider: An Abstraction With Roles and Responsibilities
A Configuration Provider hides the source, returns typed settings, validates required values, and reports useful errors. Composed providers let each system select its settings.
Chapter20 September 2017
Architecture Layers in C#
Structure communicates intent: strict layers from Domain Facade to Gateway, internal by default with a public surface the compiler enforces, and folder depth that marks each class's level of abstraction.
Chapter20 September 2017
Class Design in C#
Internal by default, behavior-only classes against state-only types, the two sanctioned uses of interfaces, and closing concrete descendants.
Chapter20 September 2017
LINQ and Query Semantics in C#
A query does not run when you write it, and calling it twice may not give the same answer. Deferred execution, materialization, terminal operators, and untranslatable queries.
Chapter20 September 2017
Method Design in C#
Explicit visibility, why public members are never virtual, orchestration over implementation, and return contracts that state their cardinality.
Chapter20 September 2017
Naming Conventions in C#
Deriving names rather than inventing them, domain suffixes over indices, the Async exception, and why Retrieve and Search choose different failure contracts.
Chapter20 September 2017
Validation and Exception Handling in C#
Where validation belongs and where it does not, exception design that fails fast and visibly, message quality, and logging that preserves the failure.
Writing10 February 2013
Factory Method Pattern: The Most Beautiful Pattern We Lost
Factory Method lets consumer subclasses choose dependencies through an overridable creation hook. C# member managers and Windows Forms show its two class families, distinguishing it from a Factory.