realm-kotlin icon indicating copy to clipboard operation
realm-kotlin copied to clipboard

Support for polymorphic inheritance

Open thipokch opened this issue 3 years ago • 1 comments

Hi!

I'm trying to use inheritance and delegation pattern in a project. Based on this comment, I assume Realm Kotlin SDK supports inheritance.

However when I tested the following patterns below with the SDK and open the file in Realm Studio, it seems that either the SDK doesn't support inheritance and delegation pattern. Can anybody please shed a light on this please?

Inheritance Pattern

open class ChildClass: RealmObject {
    var child = 10
}

class InheritedClass: ChildClass(), RealmObject {
    var parent = 20
}

Both child and parent are expected to appear in screenshot of Realm Studio. However, only parent appeared.

Screen Shot 2022-04-26 at 11 30 28 AM

Delegation Pattern


interface Interface {
    var i: String
}

class ClassImplementingInterface: Interface {
    override var i = "PleaseWork"
}

class ClassWithDelegation : Interface by ClassImplementingInterface(), RealmObject {
    var j: String = "ShouldWork"
}

Both I and J are expected to appear in screenshot of Realm Studio. However, only J appeared.

Screen Shot 2022-04-26 at 11 30 33 AM

Thanks

thipokch avatar Apr 26 '22 04:04 thipokch

Hi @thipokch. Inheritance is unfortunately not supported yet.

rorbech avatar Apr 26 '22 08:04 rorbech