Design Patterns Filter Pattern - Design Patterns

What is Design Patterns Filter Pattern?

Filter pattern or Criteria pattern is a propose pattern that enables developers to filter a set of objects using different criteria and chain them in a decoupled way through logical operation. This type of design pattern comes under structural pattern as this pattern combines many criteria to find single criteria.

Implementation

We're going to make a Person object, Criteria interface and concrete lessons implementing this interface to filter directory of Person objects.

CriteriaPatternDemo, our demo class uses Criteria substance to filter List of Person substance based on different criteria and their combination.

filter_pattern_uml_diagram

Step 1

Create a class on which criteria is to be practical.

Person.java

Step 2

Generate an interface for Criteria.

Criteria.java

Step 3

Construct concrete classes implementing the Criteria interface.

CriteriaMale.java

CriteriaFemale.java

CriteriaSingle.java

AndCriteria.java

OrCriteria.java

Step4

Apply changed Criteria and their arrangement to filter out persons.

CriteriaPatternDemo.java

Step 5

Verify the output.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Design Patterns Topics