Skip to content

Using CRTP instead of standard polymorphism #13

@giacomo-b

Description

@giacomo-b

A Curiously Recurring Template Pattern (CRTP) would probably be a better design choice instead of classic inheritance that makes use of virtual functions.

Advantage in the case of, e.g. LinearSystem and NonlinearSystem (both of which are Systems):

  1. There's need to replace System instances at runtime or to work with heterogeneous collections of Systems.
  2. CRTP would be more flexible
  3. Virtual methods imply vtable lookups at runtime. With CRTP the compiler knows which class gets instantiated, thus guaranteeing better performance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions