diff options
author | Jasper Ras <jras@hostnet.nl> | 2024-08-21 16:22:08 +0200 |
---|---|---|
committer | Jasper Ras <jras@hostnet.nl> | 2024-08-21 16:22:08 +0200 |
commit | f3711a93832df46dc245075df08b9ebfc05266e9 (patch) | |
tree | 167c4c4a9bedd6b94392b20eb6e68bc38656d456 /Zettelkast/Notes/290220240843 - Value Object.md | |
parent | 26b2ee8fe95026e84bd1721910d575db72cc1b3f (diff) |
forgot to commit for a while
Diffstat (limited to 'Zettelkast/Notes/290220240843 - Value Object.md')
-rw-r--r-- | Zettelkast/Notes/290220240843 - Value Object.md | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Zettelkast/Notes/290220240843 - Value Object.md b/Zettelkast/Notes/290220240843 - Value Object.md new file mode 100644 index 0000000..10a9afa --- /dev/null +++ b/Zettelkast/Notes/290220240843 - Value Object.md @@ -0,0 +1,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.
\ No newline at end of file |