You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: filterer/README.MD
+164-6Lines changed: 164 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
--- # this is so called 'Yaml Front Matter', read up on it here: http://jekyllrb.com/docs/frontmatter/
2
2
layout: pattern
3
-
title: Filterer Pattern
3
+
title: Filterer
4
4
folder: filterer
5
5
permalink: /patterns/filterer/
6
6
description: Design pattern that helps container-like objects to return filtered version of themselves.# short meta description that shows in Google search results
@@ -11,15 +11,173 @@ tags:
11
11
---
12
12
13
13
## Name / classification
14
-
Filterer Pattern
14
+
Filterer
15
15
16
16
## Intent
17
17
The intent of this design pattern is to to introduce a functional interface that will add a functionality for container-like objects to easily return filtered versions of themselves.
18
18
19
19
## Explanation
20
-
The container-like object needs to have a method that returns an instance of `Filterer`. This helper interface gives
20
+
Real world example
21
+
22
+
> We are designing a threat(malware) detection system. We can have different types of threats and systems. We have a requirement that
23
+
> system should be aware of threats that are present in it. In the design we have to take into consideration that new Threat types can be
24
+
> added later. Also there is a requirement that a system can filter itself based on the threats that it possesses (system acts as container-like object for threats).
25
+
>
26
+
27
+
In plain words
28
+
29
+
> We need to be able to filter different types of systems(container-like objects) based on properties of Threats that they contain.
30
+
> Adding new properties for Threats should be easy (we still need the ability to filter by those new properties).
31
+
32
+
**Programmatic Example**
33
+
34
+
To model the threat detection example presented above we introduce `Threat` and `ThreatAwareSystem` interfaces.
@@ -34,11 +192,11 @@ It enables you to easily extend filtering ability of container-like objects as b
34
192
## Known uses
35
193
One of the uses is present on the blog presented in this link. It presents how to use `Filterer` pattern to create text issue anaylyzer with support for test cases used for unit testing.
36
194
37
-
## Consequences (the good and the bad, add criticism here)
38
-
Good :
195
+
## Consequences
196
+
Pros :
39
197
* you can easily introduce new subtypes for container-like objects and subtypes for objects that are contained within them and still be able to filter easily be new properties of those new subtypes.
40
198
41
-
Bad :
199
+
Cons :
42
200
* covariant return types mixed with generics can be sometimes tricky
0 commit comments