I have a list of objects to be filtered.
This filtering will consist of at least 3 rules.
So for example:
public class Filtering { List<MyObject> myObjectList; List<MyObject> filterStep1(List<MyObject> myObjectList){ for(Myobject myobj : myObjectList){ if(isCriteriaSatisified){ continue } else { removeThisObjectFromList } } } List<MyObject> filterStep2(List<MyObject> myObjectList){ for(Myobject myobj : myObjectList){ if(isCriteriaSatisified){ continue } else { removeThisObjectFromList } } } }
I like this approach because it is simple, self-sufficient and can very easily see what it is trying to achieve.
But maybe there is a design template that I should use instead?
The Chain of Responsibility template is what I am considering when filterStep1 and filterStep2 in the above code are reorganized into a separate hander.
source share