Composition in Realm
Issue #13
There is time we have models that have some kind of inheritance, like Dog, Cat, Mouse can be Animal. We can use composition to imitate inheritance, we just need to make sure it has unique primary key
Cat and Dog
These are pretty much basic Realm objects
1 | class Dog: Object { |
Animal
Here Animal can contain either dog or cat, we can add more if there are many other “inheritance” of Animal. The required init makes sure Animal can only be init with 1 type of child class
1 | class Animal: Object { |