fretburner — 2013-04-26T19:04:26-04:00 — #1
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?
wwb_99 — 2013-04-30T12:08:49-04:00 — #2
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.
fretburner — 2013-05-02T21:21:44-04:00 — #3
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.
wwb_99 — 2013-05-11T14:09:13-04:00 — #4
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.