Using Filter Design Pattern In Java

Lets discuss another very useful design pattern named - Filter Design Pattern.

Filter Design Pattern

  • The Filter Design Pattern also known as Criteria Design Pattern.
  • The Filter Design Pattern is a design pattern that allows developers to filter a set of objects using different criteria/filter condition and chaining them in a decoupled way through logical operations. 
  • The Filter Design Pattern is a structural pattern which can combines multiple criteria to obtain single criteria.
  • With the use of Lambda Expressions in Java 8, it is actually very simple to use without even thinking this as a design pattern. But, if we are aware of the concept of filtering, we will have better understanding and command over the implementation of the code.
  • There are two different ways of creating filters
    • Filter for Entire collection.
    • Filter for single member of the collection. 
  • I will try to highlight use of lambda for filtering as well under this article. But this article is not about Java Lambda Expressions. Based on the viewer's response I may write another article to cover basics of lambdas as well. 


class filter design pattern