summaryrefslogtreecommitdiff
path: root/Zettelkast/Notes/290220240843 - Value Object.md
blob: 10a9afab1b3a37a63e70c2271b1bc71a57e8cfca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
A Value Object is a domain object that has no unique identity but if any of its properties change it is no longer the same. An example can be made with money.

```py
from dataclasses import dataclass

@dataclass(frozen=True)
class Money:
  type: str
  value: int

Money("Euro", 10) != Money("Euro", 9)
Money("GBP", 10) != Money("Euro", 10)
```

Thus such an object is a perfect candidate for immutability. With python we can add @dataclass(frozen=True). Frozen=true makes it immutable.