Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've used CRTP and some variants of it extensively both in C++, Java and C#, and from "coworkers feedback" I can tell you one thing: many people simply don't understand it, and automatically get hostile towards "such overly complicated crap".</p> <p>Until someone uses it a few times, people really find it hard to see benefits of it - just like with any other "complicated" "new" mechanism they see.</p> <p>That's true that sometimes it is used in wrong places, and that it must be used with extra care to details - but that's life of any nontrivial tool. Just like with multipleinheritance - many hate it. But how can you hate a hammer? There's nothing to hate, just use it properly and in places where it is truly beneficial, not just because you can.</p> <p>First, rethink if you really need to use it. Does the template base class really need to know the exact deriving type? Are virtual members not enough? Can you get away without it? What are the benefits in your case? Will it make the "higher level code" shorter, more readable, more obvious or more extensible or less error prone?</p> <p>In many cases, you will find that the base does not need to know the exact derived type, and you can replace it with few more virtual methods. But that could make the overall code more complicated to further users. On the other hand, with CRTP, the final mechanism are more .. 'automagical', which sometimes is actually NOT beneficial.</p> <p>In case of entity classes, often some variants of CRTP actually have a reason: if your base exposes some utility methods that return "similar" objects, you often want those methods to return refined "MyObject*" not "ObjectBase*", and that's hard to achieve without it. But, the real question is: should those methods really be in the entity's base class instead of inside the 'factory', 'manager' or 'storagecontext'?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload