SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,389
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)

    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?

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,625
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,389
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    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.

  4. #4
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,625
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •