The concept of class is used to group the properties and behavior of a particular type of domain model to enable high cohesion. A class is a blueprint that can later be used to create object instances to represent different states. A class in Kotlin will look like the following:
class Car(var color : String = "RED") {
fun accelerate() {
println("$color car is accelerating...");
}
fun brake() {
println("$color car is decelerating...");
}
fun turn(direction: String) {
println("$color car is turning $direction");
}
}
The preceding class represents a Car domain model that has the color property and the accelerate, decelerate, and turn behaviors.