Last active
April 28, 2022 09:45
-
-
Save aleksandar-b/d6e70bf292ca34bc05fedb0fae0a4e18 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Value objects | |
//Motivation | |
//Use cases | |
//Proposed syntax | |
value Money { | |
constructor(amount, currency) { | |
this.amount = amount; | |
this.currency = currency; | |
} | |
} | |
const twoDollars = Money(2, '$'); | |
const oneDollar = Money(1, '$'); | |
//Equality is defined by their properties | |
twoDollars.equals(oneDollar) // false | |
twoDollars.equals(twoDollars) // true | |
//Changeless | |
twoDollars.amount = 4; // throws exception | |
//Lack causal powers. | |
//Values can only be measured, compared and related. Methods can only return new value or boolean. | |
twoDollars.updateEntity(account) // throws exception | |
//Concept of instance does not exist for values | |
new Money(1, '$') // throws exception | |
Money(1, '$') // all good | |
//FAQ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment