A brief note on the merits of using generic types over contextual types

Introduction

Generic types can reduce the class count in any project thus allowing easier maintenance, less mapping and more consistency. It promotes code reuse in a big way.

Examples

So, to that end here are a few examples of how otherwise contextual classes can be replaced with generic types.

Generic Class

 

Usage

 

Generic Class

 

e.g.

this contextual class is no longer needed…

 

…and becomes…

 

Generic Class

 

e.g.

this contextual class is no longer needed…

 

…and becomes…

 

Generic Class

 

this contextual class is no longer needed…

 

…and becomes….

 

Conclusion

The examples presented show how generic types can promote code reuse or more specifically help prevent contextual types springing from thin air.