Protocol Buffer documentation warns that ...
You should never add behaviour to the generated classes by inheriting from them. This will break internal mechanisms and is not good object-oriented practice anyway.
source:Protocol Buffer Basics
My two part question is:
"What goes wrong" is going to be very implementation specific. If you cited a specific implementation, it might be possible to answer, but in the more general sense: this is not a supported scenario, and implementations are not required to work correctly or at all if you subclass. This is an undefined behaviour, with all that implies. Further, protocol buffers does not support inheritance, because not all target platforms can support it. Key thoughts:
SomeDerivedClass
, there's no way the serializer can give you that backAs an OO concern; this is not your type; it is a DTO that is designed to serve a specific purpose. Common usage might be to map from the DTO to/from your domain model, which can be more complex, or possibly to encapsulate the DTO if that is useful (perhaps as a façade).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With