How to implement a Business Rule?

For now the model is only static. Business rules bring life into it. A simple example of a business rule could sound like: »The amount of the per diem allowance depends on the employee’s salary«. To implement this business rule, we need a navigation path from the class PerDiemAllowance to the class Employee. We will hear more about these navigation paths in a moment.

How do we implement such business rules? The best way, we think, is to use objects. With the classes and their methods in our system we build kind of a domain language, which we can use to state business rules in a formal way, so that a computer system can understand it. But not only should the computer understand our intents, we as developers should be able to understand our own intents, after some time has passed. The following peace of code is easy to read. We can easily understand the intents behind it:

if this.Travel.Employee.Salary > 50000

    return hoursOnRoad * .6;

else

    return hoursOnRoad * .4;

Furthermore the code resides in the class PerDiemAllowance, just the place where you would look for it. If we use a data-driven approach with data sets or XML nodes, the logic of the application doesn't have a place where it can be found easily. Classes are a natural way of keeping our code well organized.