Skip to content

Loader API Design Principle #26

@wenchy

Description

@wenchy

Overview

C++

  • Protobuf C++: You cannot add behavior to the generated classes by inheriting from them, as they are final.

As https://protobuf.dev/getting-started/cpptutorial/#parsing-serialization states:

Important

Protocol Buffers and Object Oriented Design Protocol buffer classes are basically data holders (like structs in C) that don’t provide additional functionality; they don’t make good first class citizens in an object model. If you want to add richer behavior to a generated class, the best way to do this is to wrap the generated protocol buffer class in an application-specific class. Wrapping protocol buffers is also a good idea if you don’t have control over the design of the .proto file (if, say, you’re reusing one from another project). In that case, you can use the wrapper class to craft an interface better suited to the unique environment of your application: hiding some data and methods, exposing convenience functions, etc. You cannot add behavior to the generated classes by inheriting from them, as they are final. This prevents breaking internal mechanisms and is not good object-oriented practice anyway.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions