Introduction to Kotlin Object-Oriented Programming

May 22 2024 · Kotlin 1.9.21, Android 14, Kotlin Playground & Android Studio Hedgehog | 2023.1.1

Lesson 02: Classes

Demo

Episode complete

Play next episode

Next

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

You’re about to define a MuseumObject class for your MetMuseum app. In this demo, I’m using Android Studio and writing in Kotlin. To get started, open the starter project for this lesson in Android Studio.

class MuseumObject(
  val objectID: Int,
  val title: String,
  val objectURL: String,
  val primaryImageSmall: String,
  val creditLine: String,
  val isPublicDomain: Boolean
)
val obj_pd =
  MuseumObject(
    objectID = 436535,
    title = "Wheat Field with Cypresses",
    objectURL = "https://www.metmuseum.org/art/collection/search/436535",
    primaryImageSmall = "https://images.metmuseum.org/CRDImages/ep/original/DT1567.jpg",
    creditLine = "Purchase, The Annenberg Foundation Gift, 1993",
    isPublicDomain = true
  )

val obj =
  MuseumObject(
    objectID = 13061,
    title = "Cypress and Poppies",
    objectURL = "https://www.metmuseum.org/art/collection/search/13061",
    primaryImageSmall = "",
    creditLine = "Gift of Iola Stetson Haverstick, 1982",
    isPublicDomain = false
  )
@SuppressLint("ComposableNaming")
@Composable
fun showImage() {
  return if (isPublicDomain) {
    MuseumObjectComposable(obj = this)
  } else {
    WebViewComposable(url = objectURL)
  }
}
obj_pd.showImage()
obj.showImage()
var title: String,
val obj2 = obj_pd
obj2.title = "Sunflowers"
private val isPublicDomain: Boolean
obj2.isPublicDomain
See forum comments
Cinema mode Download course materials from Github
Previous: Instruction Next: Conclusion