On Mar 17, 7:22 pm, Henner Zeller <henner.zel...@googlemail.com>
> There are good reasons not to support inheritance and it would be a
> design problem if it was; so it is likely not supported.

Despite all those good reasons protobuf itself uses inheritance. All
my messages derive from google::protobuf::Message, which in turn
derives from MessageLite.

On Mar 17, 7:28 pm, Christopher Smith <cbsm...@gmail.com> wrote:
> Protobufs are basically pure data structures, with no behaviour, so
> inheritance is basically meaningless. Protobuf has other mechanisms
> for doing reuse.

Both Message and MessageLite include a lot of methods (bot virtual and
non-virtual) and entire Message behaviour is implemented by them. What
if I am building my design on top of this hierarchy and want to have
my first base message derive from google::protobuf::Message (thus
inherit its rich functionality) and then I want to have other messages
derive from my base message (inheriting functionality that I have
implemented in base message methods). I may or may not add additional
(optional) fields in derived messages - it doesn't matter now. But I
do want different derived classes to re-implement (override or
overload) some methods. In my product messages ARE data structures but
they ALSO ARE entities that have some functionality. And (up to my
understanding of OOP design principles) that functionality is better
to be implemented as those messages methods.

On Mar 17, 7:22 pm, Henner Zeller <henner.zel...@googlemail.com>
> Typically if someone has the reflex to use inheritance, they actually
> mean to do something else. So what is the exact use case you want to
> address ?

In my case I have an infrastructural class that receives messages from
a cloud and distributes them between different abstract message
processors. This  infrastructural class should not be aware of any
concrete message type. It deals with pointers/references to base type.
Currently because of this protobuf limitation I am using
google::protobuf::Message in that infrastructural class. But I need to
perform some preprocessing on each message before it will be
distributed to an end-point processor. I would very much like this
preprocessing to be implemented in a virtual method declared in base
message class and overridden in derived concrete classes. Again, I
don't want infrastructural class to be aware of concrete message types
and to cast google::protobuf::Message pointers to it.
Of course there are a lot of workarounds but we are talking here not
about workarounds, right?

You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to