TransWikia.com

Designing a filtering function

Software Engineering Asked by codeinaire on December 1, 2020

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?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP