Click here to Skip to main content
15,899,475 members
Articles / Programming Languages / C#

C# Code Reuse with a Traits Class

Rate me:
Please Sign up or sign in to vote.
5.00/5 (10 votes)
15 Apr 2021CPOL3 min read 6.5K   11  
A design pattern for C# that reuses a generic base class, modifying it using a traits class to allow changes that cannot be accomplished through overrides in an inherited class.
C# generic classes are quite useful for abstracting out type details until later use, but there is no mechanism in C# that allows non-type details to be abstracted in a similar manner. Non-type details can be overridden for instance members, but these won't be accessible to static members and during construction might not be reliable. This pattern facilitates providing the non-type details to the generic abstract base class at the time it is inherited into a concrete class, in some cases leaving nothing to be implemented in the derived class.

Views

Daily Counts

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions