0

We are working on project where we have to manage these conditions. i.e.:

A User can save an order under these conditions:

  • User has permission "SaveOrder"
  • Order is in state "shipped"
  • Online Shop is opened.

This condition is for example - I would like to point out, that we have three conditions from different areas(role and permissions, inner state of object order and state of another domain object).

In a previous project we used this code:

public static bool CanSaveOrder(Order order)
{
   return
   CurrentPrincipal.HasPermission(Permissions.SaveOrder) &&
   order.State == States.Shipped &&
   OnlineShop.IsOpen();
}

But I feel that there can be a more elegant/dynamic solution.

I have read something about a "business role engine". Is it a right way to manage this condition?

1

If you're just asking whether the same code can be formulated in a better way, that is indeed a duplicate of the question pointed out above. Read the answers to that question (and to its duplicates).

However, a business rules engine is something quite different. It means that you specify the conditions in a separate repository from the code - maybe a data base, maybe configuration files, maybe a web service - and your program only contains code to read information about how to make the decision from that repository. It will then apply the rule and return true or false depending on what it evaluates to.

This has far-reaching consequences. You can then change business logic without rewriting your program, ideally without even redeploying or restarting it. The downside is, of course, that your system depends on another external component to function, that obtaining the information from the repository may take longer, and that the code to make the decision becomes less self-explanatory than before. It depends heavily on the concrete situation whether switching to a business rules engine makes sense or not. Whether or not this is considered "elegant" is subjective, and usually not the most useful criterion to make that decision.

  • My question was about situations where some rules were frequently changing. We are building large enterprise system and sometimes our PM reproaches us for having to deploy new version of application because of change some simple rule. So I am looking for some solution, if exists. What do you think? And is there any good start to learning about roles engine. we developed in C# and asp.net. And just to be clear: I am VERY big fan of YAGNI but sometimes I feel that we have to deploy our older systems too often(i.e. small changes of tax rate). – Marek Jun 15 '13 at 15:11
0
  > "bussiness role engine". Is it a right way to manage these condition?

It depends.

"bussiness role engine" can make sense if

  • you have several instances with different definitions of "canSaveOrder" (i.e. different internetshops that use the same software)
  • the meaning of "canSaveOrder" often changes.

Otherwhise the "bussiness role engine" may violate the principles YAGNI and KISS

0

For the condition stated in the text this implementation is good, I'd even call it first choice (except for an extra tab needed for 3 rows)

Not the answer you're looking for? Browse other questions tagged or ask your own question.