diff options
author | Jasper Ras <jras@hostnet.nl> | 2024-11-23 11:30:28 +0100 |
---|---|---|
committer | Jasper Ras <jras@hostnet.nl> | 2024-11-23 11:30:28 +0100 |
commit | 1f1423fdb8d4e2928768ffa33a6ad2b59c75e82e (patch) | |
tree | 67d94f0d821a053aca0e7c8a7ffb6c369047aa14 /zettelkast/Notes/290220240843 - Value Object.md | |
parent | 93d36010a9d54bca1fdcaf1f4c99e6981aaf41bc (diff) |
lowercase dirs
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 |