Why derives from another class and this is not yet supported? #3622
-
Why derives from another class and this is not yet supported? Is it a compromise for current technical reasons or is it a design imperative? One of my model classes inherits |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The problem is that Realm doesn't support inheritance, so the current design is a compromise that explicitly expresses this restriction. The problem is that if we allowed inheritance, it would imply that one could define model properties in a base class and have them show up in all inheritors. While this is somewhat difficult to achieve in practice, it's not impossible, but then it opens the door for using the base class as the type of property/list: partial abstract class PersonBase : IRealmModel
{
[PrimaryKey]
public ObjectId Id { get; set; }
public string Name { get; set; }
}
partial class Teacher : PersonBase
{
}
partial class Student : PersonBase
{
}
partial class School : IRealmObject
{
public IList<PersonBase> Members { get; }
} The |
Beta Was this translation helpful? Give feedback.
The problem is that Realm doesn't support inheritance, so the current design is a compromise that explicitly expresses this restriction. The problem is that if we allowed inheritance, it would imply that one could define model properties in a base class and have them show up in all inheritors. While this is somewhat difficult to achieve in practice, it's not impossible, but then it opens the door for using the base class as the type of property/list: