0

I have a case where I have an existing method that does a specific kind of processing. I have setup a database table that it checks and if a specific value in a column exists it uses the value in one of the columns.

Example: let's say that I have a method that charges a user. And I have in the table a row that has a column for the country and a column for reduction percentage. So while I am processing the user if the user's country exists in the table I use the value of the column to reduce the price. So far so good.

My question is how could I enhance my design in order to add more general/complex rules?

E.g. I would like to support some kind of interface that the user specifies rules e.g. a user's age or a product weight etc and based on this rules my code processing can figure out how to apply them?

I mean how could I extend my simple table and business logic processing with the country/percentage values to a small rule based setup?

I don't need really complex rules. Just the ability to be let the define a rule if needed

Miller
  • 34,962
  • 4
  • 39
  • 60
Jim
  • 18,826
  • 34
  • 135
  • 254

1 Answers1

0

You have to support a certain set of operators, as well as possible fields to be checked against the rule and certain events when the rule is fullfilled.

I would suggest something like this: jsFiddle

<table>
    <tr>
        <td>Field</td>
        <td>
            <select><option>Country</option><option>Age</option></select>
        </td>
    </tr>
    <tr>
        <td>Operator</td>
        <td><select><option>greater than</option><option>smaller than</option><option>not empty</option></select>
        </td>
    </tr>
    <tr>
        <td>Value</td>
        <td><input id="value" type="text" /></td>
    </tr>
    <tr>
        <td>action</td>
        <td><select><option>10% discount</option><option>other stuff</option><option>other stuff 2</option></select></td>
    </tr>
</table>

That's just a very quick example of how it could look. You can add any operators and actions you want. You could also include a target field for example. But what's actually in the dropdowns depends on your requirements.

Michael Kunst
  • 2,978
  • 25
  • 40
  • @JIM Definitely there is an alternative for the same, why not design a simple rule engine and plugin the same to your product, rule engine will have its UI to create rules which can be changed every new and then depending on business needs, and then you can just leave the point open in your code where those bunch of rules can be plugged, leaving the things configurable and generic. – Ankur Singhal Jul 12 '14 at 14:21