MVVM on Android

Sep 1 2022 · Kotlin 1.6, Android 12, Android Studio Chipmunk | 2021.2.1 Patch 1

Part 1: MVVM on Android

03. Build the Model

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 02. Understand MVVM Next episode: 04. Model the Repository

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 03. Build the Model

The parameters of the Creature constructor should be var to prevent the “Cannot find setter for field error.”

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

I have the starter project for the course open up here in Android Studio 3.1.4.

data class Creature(
    val attributes: CreatureAttributes = CreatureAttributes(),
    val hitPoints: Int = 0,
    val name: String,
    val drawable: Int = 0
)
class CreatureGeneratorTest {

}
   private lateinit var creatureGenerator: CreatureGenerator
   @Before
  fun setup() {
    creatureGenerator = CreatureGenerator()
  }
class CreatureGenerator
   @Test
  fun testGenerateHitPoints() {
    val attributes = CreatureAttributes(
        intelligence = 7,
        strength = 3,
        endurance = 10
    )
    val name = "Rikachu"
     val expectedCreature = Creature(attributes, 84, name)
   }
 assertEquals(expectedCreature, creatureGenerator.generateCreature(attributes, name))

class CreatureGenerator {
    
   fun generateCreature(attributes: CreatureAttributes, name: String = "", drawable: Int = 0): Creature {
     return Creature()
  }
}
    val hitPoints = 5 * attributes.intelligence +
        3 * attributes.strength +
        4 * attributes.endurance
    return Creature(attributes, hitPoints, name, drawable)