Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any benefit to implementing RealmModel instead of extending RealmObject in Realm?

In Realm, in order for an object to be able to be persisted it must either implement RealmModel or extend RealmObject. Are there benefits to using one over the other?

All it says in the realm docs is:

An alternative to extending the RealmObject base class is implementing the RealmModel interface and adding the @RealmClass annotation.

All methods available on RealmObject are then available through static methods.

like image 757
shoe Avatar asked Sep 15 '16 20:09

shoe


1 Answers

Considering that extending any non-RealmObject classes is not possible even if you're implementing RealmModel and adding @RealmClass, in my opinion you just get additional complexity by forcing yourself to use for example RealmObject.isValid(realmObject) instead of realmObject.isValid() that you get naturally for free using extends RealmObject.

So no, you should stick to extending RealmObject. Using implements RealmModel gives you no additional benefit.

like image 192
EpicPandaForce Avatar answered Oct 31 '22 02:10

EpicPandaForce