Software design and clean code

Stage 1 · Lesson 7 of 8

Value objects and immutability

Object-oriented programming properly

A is defined by its values rather than an identity. Two Money objects holding 10 US dollars are equal, and it does not matter which one you have. Making it means it never changes after creation: adding money returns a new Money object instead of changing the old one.

Immutable objects can be shared freely, between too, because nobody can change them behind your back. Small types like Money, Email or DateRange also carry their own validation, so a bad email cannot exist anywhere in the program. Every language on this roadmap has a short way to write them.

Common trapmarking a field final or readonly while it holds a mutable list, so the "immutable" object can still change underneath you.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

Practise

  • Free exercises in your language with optional human mentoring on design, not just on passing tests

Keep handy

  • Microsoft's C# guide: the object-oriented programming and records sections

Also worth your time

Mark this stage as not done?