https://kotlinlang.org logo
Title
i

Ive Vasiljevic

12/23/2019, 1:07 PM
Is it okay to nest sealed classes. So UserData is a part of ModelData, but UserData can also have its own hierarchy with two separate types of UserData, in this case LoginData and AuthenticationData. Or is there any better solution for this?
m

Mikołaj Kąkol

12/23/2019, 1:56 PM
from my experience, it's fine 🙂
m

Matteo Mirk

12/23/2019, 2:21 PM
are you sure this example is what you want? Because
UserLoginData
and
UserAuthenticationData
do not extend
ModelData
, and if you try to assign for example an instance of
UserLoginData
to
ModelData
or do an
is
check, you’ll get a complation error. Am I missing something? 🤔
i

Ive Vasiljevic

12/23/2019, 2:35 PM
Yeah, my bad it should be
sealed class UserData(...): ModelData() {
		
		data class UserLoginData(...): UserData()
		data class UserAuthenticationData(...): UserData()
	}
m

Matteo Mirk

12/23/2019, 2:36 PM
Oh okay thanks, I was confused!