lundi 24 juin 2019

Design PAtterns for alleviating maybe changing the visibility of an object

Problem

I keep running across this paradigm where I have to write functions of the form maybeUpdateEnabled, where I change one variable that determines visibility and have to check against a load of others.

Example

Imagine I have the following data (represented as strings here for convenience):

["apple", "pear", "tomato", "celery", "red pepper"]

and I provide the user with a GUI with two toggle-buttons, one for filtering out all things that are red, and one for filtering out all things that are vegetables. The user first filters out all of the reds, and then all of the vegetables, and only pears remain. When the user then toggles the red switch, the red peppers, which were initially filtered out, should still be invisible, as they are still being hidden via the vegetable filter.

Question

Are there any Design Patterns which can help alleviate this? I was considering using bitmasks, or a stack of some kind, but I don't think I'll be able to logically avoid the maybeUpdate paradigm, which is a horrendous code smell to me.

Aucun commentaire:

Enregistrer un commentaire