Course · 26 lessons

Object-Oriented C#

Classes, structs, records, and the state an object is in.

  1. Values and references

    A value copy keeps its own bits. A reference copy names the same object.

    Objects · 8 min
  2. Classes

    A class stores values and offers a method that reads them.

    Objects · 8 min
  3. Structs

    Assigning a struct copies its fields.

    Objects · 8 min
  4. Encapsulation

    Balance changes only through Deposit.

    Objects · 8 min
  5. Interfaces

    The loop uses IBill and does not name the concrete class.

    Objects · 8 min
  6. Records

    with copies a record and changes the fields you name.

    Objects · 8 min
  7. Nullable references

    A string? may be null. ?.Length does not call Length on null.

    Objects · 8 min
  8. Pattern matching

    A switch reads fields and picks one label.

    Objects · 8 min
  9. Generics

    Holder<T> stores one T and returns that same value.

    Objects · 8 min
  10. Modeling states

    Paid and Refunded are different states of one payment.

    Objects · 8 min
  11. Constructor invariants that hold from the start

    Create domain objects only when their required state is valid.

    Designing behavior · 15 min
  12. Composition as a visible dependency

    Build behavior from collaborators instead of inheriting unrelated capabilities.

    Designing behavior · 15 min
  13. Virtual dispatch through a base reference

    Extend a genuine shared contract with an overriding implementation.

    Designing behavior · 15 min
  14. Abstract bases for incomplete shared behavior

    Require specialized types to supply the missing part of a calculation.

    Designing behavior · 15 min
  15. Polymorphic behavior without type switches

    Let each implementation satisfy one narrow operation contract.

    Designing behavior · 15 min
  16. 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
  17. Generic constraints that enable useful operations

    State what a type parameter must support before using its capabilities.

    Designing behavior · 15 min
  18. Value equality for a named identifier class

    Keep Equals and GetHashCode consistent when a class represents a logical value.

    Designing behavior · 15 min
  19. Natural ordering with a tie-breaker

    Implement comparison as a complete, predictable ordering rule.

    Designing behavior · 15 min
  20. Immutable updates with an ordinary class

    Return a new validated value instead of modifying an existing snapshot.

    Designing behavior · 15 min
  21. Events and subscription lifetime

    Observe state changes and explicitly release a subscription when it is no longer needed.

    Designing behavior · 15 min
  22. A custom enumerable with yield return

    Expose a sequence contract without exposing mutable internal storage.

    Designing behavior · 15 min
  23. Delegates for a small replaceable calculation

    Pass one focused behavior as a value when a whole strategy object is unnecessary.

    Designing behavior · 15 min
  24. Strategy objects with their own configuration

    Package a replaceable policy when it has meaningful state or several related rules.

    Designing behavior · 15 min
  25. Explicit interfaces for separate object roles

    Expose focused capabilities without placing every member on the concrete public surface.

    Designing behavior · 15 min
  26. An aggregate that owns its mutations

    Protect a small cart’s invariants and return independent report snapshots.

    Designing behavior · 15 min