Whenever you want to represent a hierarchy of types with super and subclasses, you can use the Kotlin sealed class architecture. A sealed class is designed to be used as a superclass. All of its subclasses must be declared in the same file as the superclass, either as nested classes or as independent classes.
- [Instructor] When you want to represent…a hierarchy of types,…with super and subclasses,…you can use Kotlin's sealed class architecture.…A sealed class is designed to be used as a superclass.…All of the class's subclasses must be declared…in the same file as the superclass,…either as nested classes or as independent classes.…I'll demonstrate this…using this version of my clothing item class,…which I first created in last week's tip.…This time, my enum for clothing types…only has two possible values: shirt and pants.…
And in my main activity,…I'm creating a clothing item with a type of shirt,…by passing in that value from the enumeration.…I'm going to change this…from a data class to a sealed class.…Now the first effect this has is to make the class abstract.…It can't be instantiated directly.…And if I go back to main activity,…I'll now see that there's an error.…It's telling me that the constructor is private.…It can't be called from another context.…Now go back to the clothing item class,…and I'll make one other important change.…
Skill Level Intermediate
Q: Why can't I earn a Certificate of Completion for this course?
A: We publish a new tutorial or tutorials for this course on a regular basis. We are unable to offer a Certificate of Completion because it is an ever-evolving course that is not designed to be completed. Check back often for new movies.
Android App Development: Data Persistence Librarieswith Annyce Davis4h 52m Intermediate
Building Android Apps with Cloud Serviceswith Albert Lo2h 37m Intermediate
1. Android Development Tips Weekly
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.