0
Why is data class considered a code smell?
Hello,
Thank you for all the work on the website. I really enjoy learning and repeating the patterns with Refactoring Guru :)
However, I would like to ask why data class is code smell in your opinion? This notion is similar to entities or DTOs, in my opinion data classes serve their purpose as representing a read-only entity in the system. Also, I don't understand the treatment part.
For example, in a silly language like JS/TS, let's say that I want to map an API response to something "real", rather than using plain Record<string, unknown> or whatever. I want to represent the data coming from the outside and map it to something tangible, possibly with some additional getters to get the derived data from it - actually to keep the code organized.
My humble question is: why is that bad? Why should I feel bad about using this pattern? What is the alternative? Some languages actually encourage use of data classes, for example Python or Kotlin. I don't understand the treatment and payoff here. Do you have some examples?
Kind regards,
Ralf
Thank you for all the work on the website. I really enjoy learning and repeating the patterns with Refactoring Guru :)
However, I would like to ask why data class is code smell in your opinion? This notion is similar to entities or DTOs, in my opinion data classes serve their purpose as representing a read-only entity in the system. Also, I don't understand the treatment part.
For example, in a silly language like JS/TS, let's say that I want to map an API response to something "real", rather than using plain Record<string, unknown> or whatever. I want to represent the data coming from the outside and map it to something tangible, possibly with some additional getters to get the derived data from it - actually to keep the code organized.
My humble question is: why is that bad? Why should I feel bad about using this pattern? What is the alternative? Some languages actually encourage use of data classes, for example Python or Kotlin. I don't understand the treatment and payoff here. Do you have some examples?
Kind regards,
Ralf
Service d'assistance aux clients par UserEcho