Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a name for this pattern of using generics?
    primarykey
    data
    text
    <pre><code>//this class (or interface if you like) is set up as generic... public abstract class GenericBase&lt;T&gt; { public T PerformBasicTask(T in) { ... } } //... but is intended to be inherited by objects that close the generic... public class ConcreteForDates:GenericBase&lt;DateTime&gt; { public DateTime PerformSpecificTask(DateTime in) { ... } } //... so that consuming code never knows that a generic is involved var myDateConcrete = new ConcreteForDates(); //look ma, no GTP! //These two methods look alike, and there is no generic type inference, //even with PerformBasicTask(). var basicResult = myDateConcrete.PerformBasicTask(DateTime.Now); var specificResult = myDateConcrete.PerformSpecificTask(DateTime.Today); //does not compile because T is understood by inheritance to be a DateTime, //even though PerformBasicTask()'s implementation may well handle an int. var anotherBasicResult = myDateConcrete.PerformBasicTask(1); </code></pre> <p>I've seen and used this pattern several times, and it's very useful for providing common functionality across a series of type-specific subclasses. For instance, this could be a model for Controllers/Presenters specific to a type of domain object that is central to the page(s) the class is used to control; basic operations like retrieval/persistence may use 100% common functionality, but binding/unbinding may be very specific. </p> <p>Is there a name for this pattern of generic declaration without exposing the generic to the end user?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    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