What benefits would we gain if this example was mutable? Or, would it make DateTime worse, if calling $dateTime->modify("+1 day") would return a new instance of DateTime instead of altering it's inner state?
Not in cases that setters and gettings will be valuable. In this case, using setters won't be of much importance. In the case that you want setters to be used, the emphasis on constructor injection is less as compared to settor injection.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks Oliver!
I'm curious, why do you think it's essential that value objects are mutable?
What benefits would we gain if this example was mutable? Or, would it make
DateTime
worse, if calling$dateTime->modify("+1 day")
would return a new instance ofDateTime
instead of altering it's inner state?Not in cases that setters and gettings will be valuable. In this case, using setters won't be of much importance. In the case that you want setters to be used, the emphasis on constructor injection is less as compared to settor injection.