Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discussion: Mutable<Collection> vs. <Collection> #488

Open
cmelchior opened this issue Oct 6, 2021 · 0 comments
Open

Discussion: Mutable<Collection> vs. <Collection> #488

cmelchior opened this issue Oct 6, 2021 · 0 comments

Comments

@cmelchior
Copy link
Contributor

cmelchior commented Oct 6, 2021

While writing up my presentation for the Kotlin SDK, it got me thinking about some design choices we made so.

This is around the naming of our collections.

Right now we have

  • Realm / MutableRealm (which fits the general split promoted by Kotlin and make it more typesafe)

But for collections we have

  • RealmList<T> (Which mirrors the Java API, but doesn't really match the normal pattern in Kotlin)

Would it instead make sense to make the split between

  • RealmList / MutableRealmList
  • RealmSet / MutableRealmSet
  • RealmMap / MutableRealmMap

With our current API, it doesn't really make sense with such a split as model classes don't support immutable lists, but with Projections coming in a not-too-distant-future, I could see the distinction being valuable there, e.g.

// Entity model class
class Person: RealmObject {
  @PrimaryKey
  var name: String
  val children: MutableRealmList<Person> = mutableRealmListOf()
}

// Read-only projection, with the read-only semantics expressed in the typesystem.
@Projection(Person::class)
class PersonView {
  val name: String
  val children: RealmList<Person>
}

Anyway, just a thought, and not something that is critical in the short term. But what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant