There seem to be 2 techniques to effect pseudo-inheritance/polymorphism.

oneof:

message Animal {
    string name = 1;
    oneof animal_type {
        Bird bird = 2;
        Dog dog = 3;
    }
}
message Bird {
    bool can_fly = 1;
}
message Dog {
    string breed = 1;
}

mixin common fields:

message Animal {
  string name = 1;
}

message Bird {
    Animal animal = 1;
    bool can_fly = 2;
}

message Dog {
    Animal animal = 1;
    string breed = 2;
}

Using oneof makes it easier to define a generic collection of Animals, 
though all the subtypes need to be defined by the author of Animal.
Using the mixin strategy makes it easier for any "subclass" to extend the 
base type.

I'm trying to understand all the tradeoffs and am curious if people have 
developed best practices on this. Are there other considerations?

jeff

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to