Extension methods as a name involve expanding the functionality or usability of the target type.
- These methods can be added later (than the time the type was created) after the type is already published.
- They can be written by different groups of people.
- Extension methods can target interfaces. (An alternative would be to have a common base type having these methods or reimplementation in each type).
- Different people can distribute the same type in different ways according to their needs.
The proper use of extension methods can remove orthogonal clutter from the actual type definition / implementation (instead of focusing the main type functions in the type definition).
Take LINQ as an example — by providing extension methods to IEnumerable
, it can target a huge number of types already published (and a huge number of types that may be written in the future); it separates an orthogonal problem, such as a type request from an actual type.
VinayC
source share