# Kotlin Sealed Classes | raywenderlich.com

**URL:** <https://forums.kodeco.com/t/kotlin-sealed-classes-raywenderlich-com/57543>\
**Category:** 🎓 Courses & Articles\
**Created:** [December 12, 2018, 9:51pm UTC](https://forums.kodeco.com/t/kotlin-sealed-classes-raywenderlich-com/57543 "2018-12-12T21:51:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![macsimus](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/macsimus/32/109104_2.png) [@macsimus](https://forums.kodeco.com/u/macsimus)\
**Post date:** [December 12, 2018, 9:51pm UTC](https://forums.kodeco.com/t/kotlin-sealed-classes-raywenderlich-com/57543/1 "2018-12-12T21:51:12Z")

</div>

In this Android tutorial, see how to use Kotlin sealed classes to create limited hierarchies that act like enums but allow you to create multiple instances.

* * *
This is a companion discussion topic for the original entry at [https://www.raywenderlich.com/75657-kotlin-sealed-classes](https://www.raywenderlich.com/75657-kotlin-sealed-classes)

---

<div class="post-metadata">

**Author:** ![simplekjl](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/simplekjl/32/81494_2.png) [@simplekjl](https://forums.kodeco.com/u/simplekjl)\
**Post date:** [June 5, 2019, 1:35am UTC](https://forums.kodeco.com/t/kotlin-sealed-classes-raywenderlich-com/57543/2 "2019-06-05T01:35:46Z")

</div>

This tutorial is really good! is there any recommended tutorial can you suggest for MVI?  
thanks!

---

<div class="post-metadata">

**Author:** ![macsimus](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/macsimus/32/109104_2.png) [@macsimus](https://forums.kodeco.com/u/macsimus)\
**Post date:** [June 5, 2019, 2:06am UTC](https://forums.kodeco.com/t/kotlin-sealed-classes-raywenderlich-com/57543/3 "2019-06-05T02:06:36Z")

</div>

hi @simplekjl thanks for the question!

We have a tutorial that covers MVI here: [https://www.raywenderlich.com/817602-mvi-architecture-for-android-tutorial-getting-started](https://www.raywenderlich.com/817602-mvi-architecture-for-android-tutorial-getting-started)

We also have a video course: [https://www.raywenderlich.com/266607-mvi-on-android](https://www.raywenderlich.com/266607-mvi-on-android)

And MVI is discussed extensively in our book “Advanced Android App Architecture”: [https://store.raywenderlich.com/products/advanced-android-app-architecture](https://store.raywenderlich.com/products/advanced-android-app-architecture)

Thanks again for the question!

---

<div class="post-metadata">

**Author:** ![cupofjoe](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/cupofjoe/32/110937_2.png) [@cupofjoe](https://forums.kodeco.com/u/cupofjoe)\
**Post date:** [April 28, 2020, 5:04pm UTC](https://forums.kodeco.com/t/kotlin-sealed-classes-raywenderlich-com/57543/4 "2020-04-28T17:04:08Z")

</div>

Thanks for doing this! It reminds me of the C++ days where you had to turn ON polymorphism with the key word ‘virtual’ but in Java you turned it OFF with the key word final.

C++ had the concept of ‘inline’ which is a lot like how Java does final static values. At the compiler level it just copies that code ‘inline’. A common bug around that was to not do a ‘clean’ build and an old .class file (Java) would have the OLD static final value.

I remember reading about how the Math package in Java was made final for large speed improvements.

Sealed Classes makes me think I get my cake and can also eat it. 🙂

Sadly, I think nobody talks anymore about VTables and the cost of late binding. Objective C has a really cool feature where you can change the VTable array to put your own behavior in EVEN if it is a legacy API call which is pretty neat. (Method Swizzling)

Interesting how the Kotlin authors tried to go for this ideal ‘sweet spot’. I would think this optimizes many things including compile time, run time optimizations as well as very maintainable code base.

---

<div class="post-metadata">

**Author:** ![alexkoto](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/alexkoto/32/81494_2.png) [@alexkoto](https://forums.kodeco.com/u/alexkoto)\
**Post date:** [May 25, 2020, 6:43pm UTC](https://forums.kodeco.com/t/kotlin-sealed-classes-raywenderlich-com/57543/5 "2020-05-25T18:43:00Z")

</div>

thanks , for the article  
but I have a question. I did everything step-by-step in this article.  
I don’t understend the term " limited hierarchies". Since i use “open” word, for any class i want, I can do many subclasses for a sealed class’ children too.

open class Crypto : AcceptedCurrency(){  
override val valueInDollars: Double = 3000.5  
}

class ANewClass: Crypto(){

}

I expect an error with ANewClass declaration here, but it looks ok for the IDE …

---

<div class="post-metadata">

**Author:** ![macsimus](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/macsimus/32/109104_2.png) [@macsimus](https://forums.kodeco.com/u/macsimus)\
**Post date:** [May 25, 2020, 6:58pm UTC](https://forums.kodeco.com/t/kotlin-sealed-classes-raywenderlich-com/57543/6 "2020-05-25T18:58:52Z")

</div>

Thanks for the question, @alexkoto! The word “limited” in this case means finite or small, as in finite or small in number. As in, there will only a known small number of subclasses.

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [May 25, 2020, 7:05pm UTC](https://forums.kodeco.com/t/kotlin-sealed-classes-raywenderlich-com/57543/7 "2020-05-25T19:05:01Z")

</div>

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [May 25, 2020, 7:05pm UTC](https://forums.kodeco.com/t/kotlin-sealed-classes-raywenderlich-com/57543/8 "2020-05-25T19:05:03Z")

</div>


