Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Filter with Internal Dependency
1. “Filter with Internal Dependency” Design Pattern
This is reference documentation for “Filter with Internal Dependency” Design Pattern.
Jayasree Perilakkalam
2. Description of the problem
• Filter a list to a sub-list
• Filter criterion is based on the presence of some list entries.
e.g.
{paintingR, paintingB, paintingG} returns {paintingR, paintingB, paintingG}
{paintingR, paintingB} returns {}
{paintingB, paintingG} returns {}
{paintingR, paintingG} returns {}
{paintingR, paintingB, paintingG, painting1R, painting1B, painting1G} returns {paintingR, paintingB, paintingG,
painting1R, painting1B, painting1G}
{paintingR, paintingB, paintingG, painting1R, painting1G} returns {paintingR, paintingB, paintingG}
{paintingR, paintingB, painting1R, painting1B, painting1G} returns {painting1R, painting1B, painting1G}
3. Solution
• Define an abstraction as follows:
Filter implementation
for (1…n in the list) {
“FilterMethod” (described below) returns true/false. If true add to sub-list, otherwise skip it.
}
FilterMethod
inputs: listEntry, list
method: examines if listEntry has corresponding matching entries and if yes, returns true.
4. Conclusion
• There are other ways to solve this problem.
• Another way to solve this problem is to attach “active” attribute to
each list entry and manage the “active” attribute externally whenever
the matching entries are added/changed/removed. This way involves
dependency on a routine/program that manages the “active”
attribute.
• Any questions/comments/suggestions are welcome via the comments
section below.