Object-Oriented C#
Classes, structs, records, and the state an object is in.
- Values and references
A value copy keeps its own bits. A reference copy names the same object.
Objects · 8 min - Classes
A class stores values and offers a method that reads them.
Objects · 8 min - Structs
Assigning a struct copies its fields.
Objects · 8 min - Encapsulation
Balance changes only through Deposit.
Objects · 8 min - Interfaces
The loop uses IBill and does not name the concrete class.
Objects · 8 min - Records
with copies a record and changes the fields you name.
Objects · 8 min - Nullable references
A string? may be null. ?.Length does not call Length on null.
Objects · 8 min - Pattern matching
A switch reads fields and picks one label.
Objects · 8 min - Generics
Holder<T> stores one T and returns that same value.
Objects · 8 min - Modeling states
Paid and Refunded are different states of one payment.
Objects · 8 min - Constructor invariants that hold from the start
Create domain objects only when their required state is valid.
Designing behavior · 15 min - Composition as a visible dependency
Build behavior from collaborators instead of inheriting unrelated capabilities.
Designing behavior · 15 min - Virtual dispatch through a base reference
Extend a genuine shared contract with an overriding implementation.
Designing behavior · 15 min - Abstract bases for incomplete shared behavior
Require specialized types to supply the missing part of a calculation.
Designing behavior · 15 min - Polymorphic behavior without type switches
Let each implementation satisfy one narrow operation contract.
Designing behavior · 15 min - Manual dependency injection for repeatable tests
Pass a controlled source of time instead of reading a global clock inside a calculation.
Designing behavior · 15 min - Generic constraints that enable useful operations
State what a type parameter must support before using its capabilities.
Designing behavior · 15 min - Value equality for a named identifier class
Keep Equals and GetHashCode consistent when a class represents a logical value.
Designing behavior · 15 min - Natural ordering with a tie-breaker
Implement comparison as a complete, predictable ordering rule.
Designing behavior · 15 min - Immutable updates with an ordinary class
Return a new validated value instead of modifying an existing snapshot.
Designing behavior · 15 min - Events and subscription lifetime
Observe state changes and explicitly release a subscription when it is no longer needed.
Designing behavior · 15 min - A custom enumerable with yield return
Expose a sequence contract without exposing mutable internal storage.
Designing behavior · 15 min - Delegates for a small replaceable calculation
Pass one focused behavior as a value when a whole strategy object is unnecessary.
Designing behavior · 15 min - Strategy objects with their own configuration
Package a replaceable policy when it has meaningful state or several related rules.
Designing behavior · 15 min - Explicit interfaces for separate object roles
Expose focused capabilities without placing every member on the concrete public surface.
Designing behavior · 15 min - An aggregate that owns its mutations
Protect a small cart’s invariants and return independent report snapshots.
Designing behavior · 15 min