I have recently stumbled upon a use case of extension methods and wanted to gather some design thoughts.
The problem:
A IEnumerable of a POCO and within that list there should exist a POCO that satisfies a condition say POCO.IsTheRightOne == true
.
You could write and extension class for this query
public static class POCOExtensions
{
public static bool GetIsTheRightPOCO(this List<POCO> source){
return source.Single(poco => poco.IsTheRightOne == true).UsefulProperty;
}
}
Now this to me is clean. It is easily testable, their is no need for a utils or helper class to be in the middle, the logic is encapsulated, and no side effects or other classes are needed.
Another way I could go about this is create a POCOList class and wrap the behavior in that and then you would get the same benefits and still have the ability to override behavior if needed. But since this is a poco class chances of me needing that are pretty slim.
Something about this pattern though just doesn't sit right with me. I feel like I'm paying a unseen cost. What other drawbacks to this design am I missing?