Professional Documents
Culture Documents
-------------------------------
In software design the Criteria design pattern is a design pattern that enables you to filter a set of
objects, using different criteria, chaining them in a decoupled way through logical operations. This
pattern is used in specific scenarios where the extract of one or more entities depends on the business
needs.
Purpose :
-------
Filter a set of objects, using different criteria, chaining them in a decoupled way. Allow criterion
reutilization and inheritance through logical operations (and, or, not). Generate a legible and extendable
way of adding or removing logics to filter sets of objects.
Motive:
-------
We frequently need to filter sets of objects of the same family (base class) using similar criteria but
different order and/or conditions. Usually, the logic being used for filter is a key process or a complex
process - like the planning criterion in an Operating System or the priority management in a request
queue can be. Another reason would be to be able to change in the logics used for the object filtering, in
the future, either by adding/modifying existing criterion or by adding new criterion This pattern places
great emphasis in the extent and reutilization of criterion as well as in the code legibility.
Pros:
----
Extensibility
Legibility
Criterion reutilization
Ease of doing unit tests (each criterion can be tested independently, the pattern ensures collective use
Enabling run-time criteria (depending on the programming language)
Structure:
---------