How to Make Your Code Clean With Kotlin Sealed Classes

preview_player
Показать описание
In this video you will learn how you can make your code cleaner using Kotlin sealed classes.

⭐ Get certificates for your future job
⭐ Save countless hours of time
⭐ 100% money back guarantee for 30 days
⭐ Become a professional Android developer now:

💻 Let me personally review your code and provide individual feedback, so it won't backfire and cost you a fortune in future:

Subscribe to my newsletter for regular Android, Kotlin & Architecture advice!

Join this channel to get access to perks:

Regular live codings on Twitch:

Join my Discord server:

You like my free content? Here you can buy me a coffee:

00:00 - Introduction
00:18 - Sealed classes vs. enum classes
07:23 - Using sealed classes to handle responses
10:41 - Exposing state in a ViewModel
14:58 - Making your code more readable
Рекомендации по теме
Комментарии
Автор

I was really struggling to understand sealed classes, but now I can even explain to someone else after watching the video. Thanks Phillip

francismwangi
Автор

OMG, you made the video on topic I requested in one of your recent videos.
Thank You Philipp 😊

jatinvashisht
Автор

Enum classes limit instantiation. Sealed classes limit inheritance.

petejewel
Автор

Thank you, Philipp ! 12:00 important info that is sealed class could be only one of the states you declared, but in data class you can use to define stated that could happen in one time and also declare there states in sealed classes if u need behavior of sealed that I said above

niksha
Автор

16:50 "I don't know, there are so many now a days" 😂😂

AmitJayant
Автор

I just today wanted to learn about sealed classes and here you are.

АлексейРодионов-ыо
Автор

I am always happy to be welcomed back to your new video 🤓

chrisfelix
Автор

I was not using them because I was not understanding them clearly. And, that is over now. Thanks Phil.... :)

sooshil
Автор

tysm !! I was looking for the best tutorial for sealed classes and here it goes :) !! u r bringing smiles to android dev's crazy life !! Thanks a ton, buddy !!

bjugdbjk
Автор

I always wait for your new videos. thank you so much. i love it!

keepgoingman
Автор

I thought that I knew the use of sealed class. But it went wrong after this video 🤭🤭

Thank you Philipp

venkatesh
Автор

Very cool video
I don't use sealed classes usually put after this video i will use it more
Thank you Bro
I wish you all the best

mustafaammar
Автор

What is the thought for naming the Success/Fail data wrapper "Resource"? I see this similar technique with the same name (Resource) in other blogs and tutorials. "Result" seems a more intuitive name - but I see that Kotlin already has a built-in type class called "Result" with a very similar structure as the "Resource" code. Why not use the built-in Result and why name this Resource?

ubersticks
Автор

thanks. but when get data from API to data class response, how can the field knows which object sealed class to use?
for example, json response { name: 'Khalifa', gender: 'male' } with our sealed class Gender { Male, Female }
is it automatically serialize base the object name?

bboydarknesz
Автор

I use it to listen to distinguish between Loading, Success and Failure states using when via collecting the flow as State :)

pentexnyx
Автор

The general problem of teaching to a language capability nowadays is providing a cookbook approach. I will show you how to use sealed classes. Oh, cool. Imagine we have a car class and... Okay, why do not show it in a different way. Show class of problems sealed classes can help you to solve.

kamertonaudiophileplayer
Автор

<3 I love your classes, Soon I going to present to a job offer due to your content c:. Literally, you changed my life c:

juancaos
Автор

But why not to use enum in example with Gender? It should be more concise.

GoodGuyFinishFirst
Автор

Am I the only one who saw Mia Khalifa in the list of persons at 8:58? xD On a serious note, thank you for these content Phillip. :)

damercy
Автор

hi Philipp, thank you the nice tutorial, I'm struggling with BaseActivity, BaseFragment, BaseViewModel and Almost every thing with prefix Base, Struggling to understand and write code in internship for my organization, 🙏 please make a video to clear this Base Prefix.

pradeep