-
-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make data classes in db package immutable #1210
Comments
While it's not shown in the examples, they don't say that it's outright "bad" to use mutable properties for the room data class entities and I think it's quite convenient to be honest. We can make all of them immutable, but we would have to create copies of the original entity objects every time we want to change values. So localHomeset.displayName = ...
localHomeset.privBind = ...
homeSetRepository.insertOrUpdateByUrl(localHomeset) becomes val newLocalHomeset = localHomeset.copy(
displayName = ...,
privBind = ...
)
homeSetRepository.insertOrUpdateByUrl(newLocalHomeset) and I don't really see the benefit in that. In the PR I have made the properties immutable which are not updated. |
While I agree that it's convenient (which is probably the reason why they are not immutable at the moment), I wonder whether it's a sign of bad design when data transfer objects are used as a place where modifications etc happen. When we pass for instance a I found a lot of article about this topic out there, with different conclusions. So it seems like a matter of taste. Another question, if we'd choose mutability, is: which properties should be mutable and which not? Or probably just So I'd go either the one or the other way, but mixing (like in the current codebase, where we have many So what do you think? Also @ArnyminerZ |
I do not have a strong opinion on this. I like the ease of use with mutable properties, but also see the security/stability immutability brings. I am fine with either. |
Ok, so let's make them immutable :) |
I'd stick with immutable for all data classes. Even though that it's a bit more code, I think it can lead to better practices. Mainly for lists, which I think is what has most issues with Compose.
In that regard, since I don't think is ever good to mix |
Currently we have
var
properties in the database entity data classes.I think there should be only immutable data classes, at least they're immutable in the documentation.
The text was updated successfully, but these errors were encountered: