Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider different inheritance patterns #75

Closed
arcondello opened this issue Jul 26, 2024 · 1 comment · Fixed by #74
Closed

Consider different inheritance patterns #75

arcondello opened this issue Jul 26, 2024 · 1 comment · Fixed by #74
Labels
enhancement New feature or request question Further information is requested or further design needed

Comments

@arcondello
Copy link
Member

arcondello commented Jul 26, 2024

There are two approaches if we want to go this direction:

Virtual inheritance

See #74 for an example.

The advantage is that we can mix several different inheritances. E.g.

struct Node {};
struct Decision {};
struct Array {};

struct ArrayNode : public Array, public virtual Node {};
struct DecisionNode: public Decision, public virtual Node {};

struct ListNode : public ArrayNode, public DecisionNode {};   //<- this is allowed with virtual inheritance.

The downside is a minor performance hit. Because now ListNode does not necessarily know where in memory the "node parts" are.

Direct inheritance

In this case we just do

struct ArrayNode : public Array, public Node {};

The upside is performance. All the array/node points know their relative position. The downside is that we cannot as easily add/compose new node types. So we end up doing things like

struct Node {};
struct Decision {};
struct Array {};

struct ArrayNode : public Array, public Node {};

struct ListNode : public ArrayNode, public Decision {};

Next steps

Performance testing needed.

@arcondello arcondello added enhancement New feature or request question Further information is requested or further design needed labels Jul 26, 2024
@arcondello
Copy link
Member Author

One way we could potentially mitigate the performance hit of virtual inheritance is with liberal use of the final keyword for classes. Though that would make maintaining binary compatibility in the future a bit more tricky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested or further design needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant