Putting it together
- Kotlin course
- Expert
- Lesson 47/47
- 6 min
Combine all expert topics into a working mini app.
Putting it together
The final lesson combines every part: the App root, the Note shared data, the NoteBuilder code generation and the noteView UI into a single main flow.
You will change the main body: combine the app name from App.run() and the note title from noteView(b.build()) in a single println. The output becomes "Expert Notes: Compose". This is a working model of the KMP + KSP + Compose combination.
The combined main flow
The combined main brings four parts into a single output: App.run() gives the name, NoteBuilder produces the data, noteView draws it.
Example: val b = NoteBuilder(); b.title = "Compose"; println("${'$'}{App.run()}: ${'$'}{noteView(b.build())}"). The output is Expert Notes: Compose. This is the full model of unidirectional data flow: root name, builder data, composable draw. This is the summary of the expert final.
Practice Write the combined main
Change the main body: do val b = NoteBuilder(); b.title = "Compose", then write println("${'$'}{App.run()}: ${'$'}{noteView(b.build())}"). The output should be Expert Notes: Compose.
Starter code
object App {
fun run(): String = "Expert Notes"
}
data class Note(val id: Int, val title: String)
annotation class AutoBuilder
class NoteBuilder {
var id = 0
var title = ""
fun build(): Note = Note(id, title)
}
fun noteView(note: Note): String = note.title
// main: combine App object + NoteBuilder + noteView
fun main() {
val b = NoteBuilder()
b.title = "Compose"
println(noteView(b.build()))
}Sample solution
fun main() {
val b = NoteBuilder()
b.title = "Compose"
println("${App.run()}: ${noteView(b.build())}")
}Expected output
Expert Notes: Compose
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What is combined in the final lesson?
The final lesson combines three expert topics.- KMP + KSP + Compose Correct answer
- val, var, const
- class, object, inheritance
- Activity, Fragment, View
Explanation: The final lesson combines KMP, KSP and Compose.
2 Match the combining parts
| Term | Meaning |
|---|---|
App.run() |
App name |
NoteBuilder |
Code generation |
noteView |
UI layer |
Note |
Shared data |
3 Complete the combined println
println("${____}: ${noteView(b.build())}")
println("${App.run()}: ${noteView(b.build())}")
Explanation: ${App.run()} embeds the app name into the string.