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.…
Author
Updated
6/29/2018Released
7/14/2017Skill Level Intermediate
Duration
Views
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.
Related Courses
-
Introduction
-
Welcome43s
-
-
1. Android Development Tips Weekly
-
Play sounds with SoundPool8m 45s
-
Manage menus with when3m 44s
- 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.
CancelTake 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.
Share this video
Embed this video
Video: Create inheritance hierarchies in Kotlin