Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><em>Generics is used to re-use a behaviour that needs to be described beyond the type</em> - or at least within the restrictions enforced by the <code>where</code> clause.</p> <p>The example you have seen, IMHO, is a <strong>generics anti-pattern</strong>. Type should not matter or if it does, should only matter if it is defined in the restrictions - i.e. <code>where</code> clause.</p> <p>So basically, a generic abstract class which expects all subclasses to implement an abstract, is <strong>not using the genericness</strong>. I cannot just simply start using <code>Generic&lt;MyType&gt;</code> which is the point of generics.</p> <p>I believe that defeats the point. </p> <p>In this case there is a <strong>slight benefit</strong> in using a generic abstract class/interface and that is <strong>type safety</strong> achieve for <code>PerformSpecificTask</code>.</p> <hr> <h1>UPDATE</h1> <p>I knew it is a contentious issue and I would be fired at left and right, but I believe it is the case.</p> <p>A class can happily subclass a generic class and add more functionality. But in this case, it is the <strong>extra functionality that defines the identity of that class.</strong> When I cannot just say <code>Generic&lt;MyOwnTypeOfVolition&gt;</code> then I have defeated the objective of generics. Sometimes, however, it is not the generics which I am concerned with - it is the <strong>interface</strong> which seems to be the case here.</p> <hr> <h1>UPDATE 2</h1> <p>A classic example, is <code>IConvertible</code> in .NET Framework. </p> <p>You could setup a generic interface/abstract class for it and ask all subclasses to implement it, but the framework makes it an optional case and supports it only for classes implementing the interface.</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. 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