polymorphic? KillerWhale : Monster

204 views
Skip to first unread message

chbfiv googl

unread,
Apr 12, 2015, 10:05:38 PM4/12/15
to flatb...@googlegroups.com
Just curious if this can support polymorphic objects?

e.g.,
KillerWhale : Monster

Any recommendations if not how to support it while still using flatbuffers? Just force schemas to duplicat fields in the super classes? Pros/Cons?

Thanks,
Bourke


Wouter van Oortmerssen

unread,
Apr 13, 2015, 1:33:32 PM4/13/15
to chbfiv googl, flatb...@googlegroups.com
There's no form of inheritance currently supported, no.

The problem with inheritance that at least in the naive case (where you'd copy all fields from base class to derived) you'd have to freeze the base class, since adding any fields to the base class would shift all fields in the derived class, which is an incompatible change. You can of course assign explicit field ids, and make sure you start ids for derived tables with "some room" from the base, but this is clumsy too.

A more robust way to make a derived table is to simply have an instance of the base be the first field of the derived, though of course that doesn't make them compatible/polymorphic. One thing we could consider is to officially support this pattern by generating accessor methods on the derived table that can indirect to the base table, but that doesn't sound super helpful/efficient either.

--
You received this message because you are subscribed to the Google Groups "FlatBuffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

lessc...@googlemail.com

unread,
Oct 26, 2017, 4:50:37 AM10/26/17
to FlatBuffers
..still polymorphism or overloading of objects or methods in flatbuffers is not supported yet, see e.g. here by 2016: https://github.com/google/flatbuffers/issues/4006

Wouter van Oortmerssen

unread,
Oct 26, 2017, 1:12:40 PM10/26/17
to lessc...@googlemail.com, FlatBuffers
There are no plans to support this, for more detail see the answers by gwvo on the issue linked above.

Fundamentally, FlatBuffers objects are things that live in buffer and require strict forwards/backwards compatibility in layout, which are both incompatible with the concept of inheritance as present in most languages.


--
You received this message because you are subscribed to the Google Groups "FlatBuffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages