Working with data classes
In Kotlin, it's recommended to use data
classes as the representation for your entities. In our case, we did not use data
classes since we extended a common class containing the attributes shared between the Note
and Todo
classes.
We recommend the use of data
classes since it can significantly simplify your work routine, especially if you are using these entities in backend communication.
It's not rare that we have a need for classes that have only one purpose--holding the data. The benefit of using data
classes is that some functionality that is often used along with its purpose is automatically provided. As you probably already know how to define a data
class, you have to do something like this:
data class Entity(val param1: String, val param2: String)
For the data
class, the compiler automatically provides you with the following:
- The
equals()
andhashCode()
methods - The
toString()
method in human readable form,Entity(param1=Something, param2=Something)
- The
copy(...