在Realm
中,爲了能夠堅持對象,它必須執行RealmModel
或擴展RealmObject
。使用其中一種有好處嗎?實現RealmModel而不是在Realm中擴展RealmObject有什麼好處嗎?
所有它在realm docs說是:
到延伸的RealmObject基類實現RealmModel接口並添加@RealmClass註釋的備選。
上RealmObject可用的方法都然後可以通過靜態方法。
在Realm
中,爲了能夠堅持對象,它必須執行RealmModel
或擴展RealmObject
。使用其中一種有好處嗎?實現RealmModel而不是在Realm中擴展RealmObject有什麼好處嗎?
所有它在realm docs說是:
到延伸的RealmObject基類實現RealmModel接口並添加@RealmClass註釋的備選。
上RealmObject可用的方法都然後可以通過靜態方法。
考慮到extending any non-RealmObject
classes is not possible even if you're implementing RealmModel
and adding @RealmClass
,在我看來,你只是強迫自己使用例如RealmObject.isValid(realmObject)
,而不是realmObject.isValid()
您得到自然的免費使用extends RealmObject
獲得額外的複雜性。
所以不,你應該堅持延伸RealmObject
。使用implements RealmModel
不會帶來額外的好處。
目前'RealmModel'的唯一好處是你可以擁有自己定製的'isValid()'。如果你擴展'RealmObject',你不能在你自己的類中使用這種方法。 –
我想'isManaged()'和'isLoaded()'(和'deleteFromRealm()')也是這樣。 – EpicPandaForce
是的,它適用於'RealmObject'上的所有方法,因爲我們把它們都做成了final。 –