Deep Diving into MVVM
We have already seen the MVVM layers and their pros and cons. In this section, we are going to implement the MMVM architecture in our app step by step. We will start with the model layer, going upwards. Since we all love to have the company of our pets, we are going to use different types of pets as our data.
Let us start by creating a data package for our project. We’ll do this by right-clicking the com.packt.chapterfive
package; then, we select New | Package and name it data
. Inside this data
package, let us create a Pet
data class that will represent our pets:
data class Pet( val id: Int, val name: String, val species: String )
The Pet
data class holds all the data for our pets. Next, we will create a repository interface and its implementation that allows us to get these pets. Create a new file named PetsRepository
inside the data
package with the following code:
interface...