3

This question is not so much about how to implement a solution as I've already implemented a working solution, but more about how to improve how I implemented it. The implementation process of the requirements was haphazard. That was partly due to unclear requirements and partly due to an unclear preexisting partial solution by another developer.

Recently, I completed a small web app for a client that was used to filter through a list of objects. The interface allowed a user to select what to filter for in the list of objects. There was a base filter and a sub-filter that used the criteria in the base filter as well as their own.

This is what was available to filter in the base filter:

  1. Max number of objects to show
  2. Criteria 1 + Max number of objects to show with Criteria 1
  3. Criteria 2 + Max number of objects to show with Criteria 2
  4. Criteria 3

1 worked with 2,3,4 while 2 and 3 worked as OR logic and 4 worked with AND logic with 2 and 3.

The sub filter had a set number of criteria all of which worked with AND logic with 2,3,4.

The process of building it was a bit convoluted and unclear so I'm wondering if there's a better way.

The general structure of it was:

  1. Check if an object can be added based on whether the 1 or Max objects of 2 or 3 has been reached.
  2. Check if the subfilter is in use and check the criteria match for it
  3. Check the base filter criteria and if any of it matches
  4. Add the object to the filtered list if 2 or 3 are true
  5. Add to the appropriate Max object for 2 or 3 and then if the Max object for number of objects to be shown
  6. Then add it to the filtered list

QUESTIONS

I'm not sure if that's enough detail but I'm wondering what's a way to approach filtering a list of objects, broadly speaking or relating specifically to the aforementioned criteria?

I notice that the filtering logic I developed to get it working as per the requirements was a bit haphazard and it seemed I had to work it out as I wrote the code and tested if it was filtering as expected. What would be a better way of designing this beforehand instead of haphazardly creating the solution as I go?

asked Sep 26, 2020 at 9:31
1
  • The complexity here would appear to be related to the limiting/"max number of objects" feature. If the numerical limit is hit, how do you specify the priority for inclusion? Also, how do the limits apply to objects which meet multiple criteria (and therefore fall to be assessed under multiple limits)? For example, if the individual limits are set to 10 items, and the overall limit set to 20 items, but the top 10 items matching each individual criteria are the same set, then do you return just 10 items overall, or do you retrieve more items to make up the overall 20 item limit? Commented Sep 26, 2020 at 10:25

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.