Search code examples
design-patternsbusiness-logicarchitecture

Where should the business rules be implemented?


1) Should them be implemented in a module over any set of their methods? 2) Should them be implemented in a special class where every method test a specific business rule?

Also... could you recommend me any good bibliography on the issue?

UPDATE:

"A business rule is a rule of a business, company, or corporation. It is a rule that defines or constrains some aspect of business and always resolves to either true or false" Wikipedia definition.


Solution

  • First you'll have to have a clear definition of what a "business rule" is. There are a bevy of candidates:

    1. Information about your products.
    2. Rules regarding sales that depend on time, location, customer, product, phase of the moon (aka closing date of the month), season, etc.
    3. User roles (e.g., normal versus preferred customers, etc.)
    4. Rules around accounts payable and receivable
    5. GAAP rules

    What exactly do you mean? It's a vague question that can be quite large if you let it.

    You have lots of choices as to where they go in your code:

    1. Data driven, stored in databases
    2. Expressions in a Rete rules engine.
    3. Middle tier classes if you're writing OO.
    4. Properties or configuration files if you're doing declarative programming.
    5. Executable rules expressed in something like JavaScript.
    6. In your ERP, MRP, A/P and A/R systems.
    7. Fronted by web services that your apps compose together.

    Do you see the problem you're opening up? Your question implies that you have a well-defined problem and expect a simple, neat answer. The truth is that it's a broad topic.