You are just applying the decorator pattern? That idea is everything but new. I am not a C# guy but the collection initializer is something pointed out directly on

I personnally don't think it is necessary to decorate a collection. Usually the service layer should take care of these things (for example validating data), as collections just represent an intermediate state of data in applications (request/response|IO, in memory or in the persistence layer).

It might even be counter productive as this pattern introduces more classes which need to be tested in addition to the service layer, which needs extra validation anyway. The way you implemented the example and making the assumption, that there are no other guards "protecting" the applications state, you would not even know that invalid data is flowing arround in the choas surrounding the collection and the collection discards the invalid values silently.

If, and only if, there is a common understanding in the team, that these kind collection extensions are necessary, a generic approach should be chosen and not a concrete decorator. These classes should be provided as NuGet package, so that the classes can and will be used by all devs in a company so that there is a common understanding and economic value.

Entrepreneur · Machine learning and software engineering for bread and butter

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store