I have a List of campaigns that need to be processed via different kinds of filters for e.g., Platform Filter, Application Filter, CampaignRunning Filter to check if the current date should be between Start Date and End Date etc.
There are ideally 15 - 20 different filters, and I am managing them using Intercept Design Pattern.
before applying filters List could be empty, so should I use NullValueFilter
in the filter chain?
after applying some filters list again can be empty, to check that also should I inject the same null or empty check strategy using the strategy design pattern?
I usually think more on designing perspective to manage such cases. I want to know if I am thinking in the right direction or maybe I am overengineering on that part.
Some pseudo code to illustrate the scenario -
Class NullValueFilter : IFilter {
Execute(List<CampaignList> campaignList) {
if(campaignList != null && campaignList.Count == 0) {
return false;
}
return true;
}
}
Class PlatformFilter : IFilter {
Execute(List<CampaignList> campaignList) {
if(campaignList != null && campaignList.Count == 0) {
return false;
}
campaignList = campaignList.Where( x => x.Platform == 'Mobile');
return true
}
}
Class CampaignRunningFilter : IFilter {
Execute(List<CampaignList> campaignList) {
if(campaignList != null && campaignList.Count == 0) {
return false;
}
// first Fetch campaign start date and end date
campaignList = campaignList.Where( x => x.startdate <= curr_date && x.enddate >= curr_date);
return true
}
}
I can think of two options here -
- create a filterbase class that can manage null and empty check for list.
- inject null value filter instance in each filter using constructor injection and call that null and empty check method.