Are there any patterns for applying multiple rules?

Hi,

I’m writing an app that has to take products from a database and export them to several different online marketplaces (Amazon, Play, etc.). I want to apply different rules about whether to include products, and how to price them, based on things like which supplier a product comes from, which market it’s going to, and what category it’s in…

I thought maybe there might be some kind of design pattern that deals with this kind of situation. I want to design something that’s going to make it easy to add new rules later on. Does anyone have any thoughts about the best way to do this?

It isn’t just one pattern, it is a number of patterns working on concert with some message queueing to make things happen.

On the front you’ll probably want to use the strategy pattern amongst other things to pick items for a vendor. You’ll likely need some adapters to reformat that data to send it. Then perhaps a facade to cover the web services on the backside. And that doesn’t even get into UIs or dealing with pricing and other things.

Thanks for the reply, and I appreciate the suggestions, but I guess I could have worded my original question more clearly. At the moment I’m just trying to find a better way to implement the pricing rules, rather than dealing with the UI and data formatting.

Say I have my collection of product objects, and I want to loop through those and apply a set of rules to each one - is there a good way to do that which will keep the code clean and maintainable? I did some research on the patterns you mentioned and I came across the Chain of Responsibility pattern - this looks like it might be a fit for what I’m trying to do.

You might want to look at the visitor pattern – if each of your product objects exposed a ProcessRule() method of some sort that would take the rule and apply it internally that could keep things real clean.