Modularizing business rules in code

This is a discussion on Modularizing business rules in code within the General Discussions forums, part of the Community Boards category; I'm facing a problem with a customer of mine that I need to somehow adddress better than I have done ...

  1. #1
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,458

    Modularizing business rules in code

    I'm facing a problem with a customer of mine that I need to somehow adddress better than I have done so far.

    At the end of the program execution, a csv file is generated with a few thousands records for later import on a central Oracle database localized in Germany. The generation of this csv file is not straightforward, however. A few business rules will alter the data or how it is generated. Three examples (there's more than that):

    - The fields in the csv file may obey a different order than the one on the local database.
    - Some date fields use MM/DD/YYYY, while others use DD/MM/YYYY
    - Phone numbers must be prefixed with '+' followed by country code.

    Since the local database, from where the data is collected for the csv generation, respects the local business rules, it's not desirable to reflect these business rules in the local database. Instead, it's the csv export functions in my program that should do the mapping. And so I have done so far.

    But these business rules are always changing, new ones being introduced, or old ones removed... with the chance of later being reintroduced. I find myself altering the code in ways I didn't want to. I need some method to this madness. What I would like to know is how would you tackle such a problem?

    I'm thinking in compartmentalize the business rules into some form of structure with pointers to functions, so that I can easily locate and change nodes, add new nodes, deactivate others (keeping them for reuse later, if I must) and create a FSM to conduct the workflow between these nodes.

    Have you ever encountered this problem where the business rules of your application are frequently mutable? What do you suggest I do?
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,740
    Since the local database, from where the data is collected for the csv generation, respects the local business rules, it's not desirable to reflect these business rules in the local database.
    In this case I would have the local database export the data and then have an external program convert that data to the desired format.

    Then write a program to modify the data. The program could read a configuration file that maps the fields to the desired changes and the method to call to preform the change. These methods might only know how to change one field or might work on the entire exported file. You would then only have to change the configuration file and write/add any new method to change the business model.

    The methods and conversion program could be written in a compiled language or even a scripting language, which ever is easier to modify tomorrow when the business model changes.

    And the configuration file could be held in a text file, XML file, or whatever you find easier to modify.

    Jim

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,458
    Quote Originally Posted by jimblumberg View Post
    In this case I would have the local database export the data and then have an external program convert that data to the desired format.
    I am already doing this programmatically for over an year. I need a design pattern.

    The methods and conversion program could be written in a compiled language or even a scripting language
    I need a in-code solution. Not introducing news problems in the form of other languages, and installing and maintaining their compilers/interpreters.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #4
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,689
    It sounds like your current idea is what you need, but compare and contrast the visitor pattern.

  5. #5
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,458
    Hmm... the visitor pattern seems perfect. The double dispatch is godsend an I can keep the workflow logic in the elements class and nicely separate the rules in visitor classes. Should probably also serve as a good base for a second phase, when I will want to move this stuff to runtime (at least changing the workflow, not adding new rules).

    Didn't give this name a second look, when I was skimming through the GoF. Should have known better. Thanks whiteflags.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Proposal: Code colouring
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 05-14-2007, 07:23 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  3. Obfuscated Code Contest: The Results
    By Stack Overflow in forum Contests Board
    Replies: 29
    Last Post: 02-18-2005, 04:39 PM
  4. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 03:17 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21