Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Problem
Immutable objects are safe to use.
Example:
If dto is immutable, one can safely remove or change the call to
service1
and be sure, that logic related tores2
is not affected. But if dto is muttable, we have to investigate all possible call chains on service1 in order to make the refactoring, because I don't know in advance how dto is mutated during the call toservice1
.The good practice is not to mutate objects which are passed as arguments to public methods. This makes maintenance much easier.
Currently, Dtos (under
src/Application
) are not immutable because they contain public setters fields of mutable types like IListI'd like
Let's replace set with init Dtos.
Let's replace
IList
withIReadOnlyCollection
all Dtos.Alternatives you've considered
No alternatives :)
We can use arguably
IReadonlyList
instead ofIReadOnlyCollection
, but I would prefer the former because it is more minimalistic.