I would like to check out some objects. The check has two parts:
- check whether the user has the right to access the object (specific rights have already been calculated and stored in logical values, there are a maximum of 4 roles)
- check if an object is in a certain state (from a set of states)
I have many rules (actually about 25 in total), such as those that need to be confirmed:
- isOwner && & (status == 11 || status == 13 || status == 14)
- ! (isOwner && isReceiver && status == 12)
- .....
For me, these rules apply to several methods, 4 or 5 rules in the method. If a rule fails, other rules are not checked. I need to build a validator (or configure an already built) in every method that uses this check.
I am looking for a design template that will make it easier to create a structure for checking objects. My goal is to provide specific error messages. For example, if the check failed, because the user does not have rights, I want to inform him about it. If this happened due to the state of the object, then I want to show that.
First of all, I mean the decorator pattern. I have an error message handler object that can be decorated with specific error messages. One decorator will check user rights, and the other for states. But the order in which I build my validator objects does not matter, so the power of the decorator template is not used. (AFAIK is one big advantage of using a decorator - mixing the scenery). I think the chain might be better for this case ...?!?! What design alternative would you recommend for this scenario?
source
share