I'm implementing a slight variation of this design pattern (filter) https://www.tutorialspoint.com/design_pattern/filter_pattern.htm
What I came across, is that I need to filter a String attribute (say, "name") of a list of objects.
The question here is, should I implement a filter/criteria class for every name in existence? I really don't think so. There should be a better and more modular way to adapt this:
See, interfaces in java require every method in them to be implemented by the classes. This means, if I want to make a NameCriteria class, I cannot give its method meetCriteria(List<Person> persons)
two parameters (like a String to filter).
Is there a practical and less hardcoded way to implement this pattern, so I can make a meetCriteria(List<Person> persons, String name)
method, or any workaround to this?
Aucun commentaire:
Enregistrer un commentaire