Skip to content

Why derives from another class and this is not yet supported? #3622

Closed Answered by nirinchev
CodingOctocat asked this question in Q&A
Discussion options

You must be logged in to vote

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 : I…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by CodingOctocat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants