I'm working on a piece of code that needs to validate whether two users are "matched" under several different criteria. If it helps, think of this as a dating app, where we are trying to match people based on age, sexual preference, ethnicity preference, etc. Here's an example with 3 conditions, each of which is a function.
def is_match(row):
return True \
and ethnicity(user_a, user_b) \
and sexual_orientation(user_a, user_b) \
and age(user_a, user_b) \
Now, let's say I want to add another condition for proximity, I would just add it to the function:
def is_match(row):
return True \
and ethnicity(user_a, user_b) \
and sexual_orientation(user_a, user_b) \
and age(user_a, user_b) \
and proximity(user_a, user_b)
Of course, this is feasible for a small application, but I can imagine a point where other co-workers may want to check out the code and pass their own conditions to it, and this doesn't seem abstract enough. I know there must be a pattern here to follow. Should I pass in each function as an array? How would you recommend doing this? I'm working in Python, but you can use any language you want to demonstrate the patterns.
Aucun commentaire:
Enregistrer un commentaire