Is it a good practice? ``` data class Property( ...
# announcements
t
Is it a good practice?
Copy code
data class Property(
    val name: String,
    val value: String
)

data class Element(
    val name: String,
    val properties: List<Property>?,
    val elements: List<Element>?  ---> REFERENCE ITSELF
)
d
Also I would just use a
Map<String, String>
instead of a
List<Property>
unless
Property
is a placeholder for something more complex than two strings.
r
@dalexander That would be semantically different. There's no indication
name
can't repeat, or it may just be that order is important and uniqueness is handled manually.
👌 1
d
You at-ed the wrong person. But I suppose that's true.
r
Yeah, the list updated right before I hit enter 😠
d
Generally something called "properties" can't / doesn't want to have duplicates though, which is why I added that.
r
Agreed. I actually have a similar issue in a project I'm working on where I have to use a List and handle uniqueness manually as being able to change the order is important, which is why it came to mind.
h
Also a data class comes with field names for the "key" and "value" which is syntactically pleasing 😉
r
So does
Map.Entry
, or am I missing your point?
h
Instead of
entry.key
you have
property.name
which is more context.
r
Ah, I see what you're saying. Sorry about that 🙂
h
I could have explained it better 🙃
When I use maps I always feel I have to write really verbose variable names
Copy code
val firstNameToNameOfFavoritePet: Map<String, String> = ...
🤔 1