How can I achieve self-documentation AND generality

Here's the issue I am stuck with, and browsing through a ton of pattern books hasn't provided a solution as best I can tell.

I have a problem that requires one of two possible solutions, and I am looking for perhaps a third that I'm not aware of. I have a set of classes that inherit from a base class, and each of these classes does some activity and returns a boolean result. The problem is that each of these classes requires a different number of inputs, from 1 to 5 in order to do their evaluation.

These classes also only accept base types as arguments (int32, double, string, boolean, etc) to avoid having them restricted in their usage. Lets call this set of classes RULE classes.

Well I am making a class that is a go-between for each of these RULE classes and a DataTable.

Here are the two possibilities I am aware of with this design.

1. This go-between can have the knowledge of which inputs are required by a particular RULE class it wants to be a front end to by making parameters reflect this, so the user will have some intellisense documentation of what is required as inputs. The problem with this solution is that this go-between class is then unable to work with more than a single RULE class. I will have to have a go-between class for each and every RULE class.

2. Make the go-between accept an arraylist or some other collection of arguments that it can then internally break down and pass to whichever RULE class it's acting as the go-between for. I don't like this solution because it requires that the client programmer using the go-between to consult the RULE class on the back side of the go-between to determine what arguments are required and in what order, and then construct this argument collection and pass it to the go-between so it can break them up and pass them to the RULE class in some predetermined order.

Both of these solutions suck. Is there a way to make a go-between accept a variable number of arguments that are also self-documenting so that I can have one go-between class work with any number of RULE classes without forcing the client programmer to consult some external documentation about how to construct the arguements for each RULE class used




Answer this question

How can I achieve self-documentation AND generality

  • coding for fun

    I would look at the combination of a specification pattern http://www.martinfowler.com/apsupp/spec.pdf in combination with a container such as spring or windsor or a basic factory to do similar things ..

    Also have you considerred (since you are using a table pattern, to just pass in a row to the rules then base the calculations off of metadata )

    Cheers,

    Greg


  • Wing_VB6

    This not so much an architecture issue as it is a design one - anyway

    One way to do that is to make all the rule classes accept some generic stucture and have each rule figure out if it can handle what was passed.

    all rules active in the system can register with the go-between and it will call them when there's a new "something" to be evaluated. (you can implement that with an event and have the rules subscribe to it)

    You can make this more specific if you group rules by thier "signature" (parameter lists) and have specific events for each signature type

    both these solutions keep the information on what a rule can handle in the rules and don't leak the knowledge to the go-between

    HTH,

    Arnon



  • Steve Sartain

    This sounds like an interesting approach I will look into further. I don't want to mark this question as answered just yet in case some other ideas come in. People tend not to add their responses to questions that are already marked answered.

    Thanks for your viewpoint.



  • Nuno Linhares

    Have you took a lok at NSpring (http://sourceforge.net/projects/nspring), NHibernate (http://www.nhibernate.org/) and similar frameworks

    They provide a certain level of generalization that might be helpful to you.



  • Frank Ran

    I am printing your PDF right now, and I am not familiar with the "table" pattern, so I will research that, read the PDF and give a response then. Thanks for your contribution. I'm sure I'm going to learn something new whether it works for this particular problem or not.



  • How can I achieve self-documentation AND generality