The filter and pipeline patterns can be optimized with code reduction using lambda expression(shortcuts for anonymous method) as concrete filter condition. To demonstrate concept, the sample WPF UI application was created. Here is Source code

Pipeline and filter pattern

Traditionally filter pattern interface is implemented for every new filter. Instead of implementing interface for every filter condition, the generic lambda expression can be used as input to filters pipeline. As result, there will be less code. The following is class diagram:

ConditionAggregator is pipeline class where it stores collection of Condition. Filter owns ConditionAggregator or Condition to apply filter conditions on data collection. When Filter apply function is called, ICondition check method is executed. ConditionAggregator has event OnFilterChanged. It is triggered when the collection or condition value is changed at view model classes. The next section will describes view model usage filter pattern.

#design-patterns #csharp #wpf #code-quality #filter-pattern #express

How To Use Filter Pattern With Generic Lambda Expression
1.30 GEEK