开发者

Schema/Code for respecting different schedules

开发者 https://www.devze.com 2023-03-10 02:28 出处:网络
We accept leads from lead providers.We only allow certain providers to post leads to us during certain days/times.Currently, we have 3 schedules, but we might add 1 or n more in the future:

We accept leads from lead providers. We only allow certain providers to post leads to us during certain days/times. Currently, we have 3 schedules, but we might add 1 or n more in the future:

    开发者_C百科
  1. Sunday @ 8AM - Friday @ 3PM -- all hours in between.
  2. Monday - Friday from 8AM - 5 PM.
  3. 24 hours a day, every day.

In addition, we want to be able to one-off certain hours -- so, we would have told some of the lead providers, "I know you normally post 8 AM - 5 PM M-F, but Monday is a holiday, so don't post then."

The problem is that some lead providers are not setup to handle a schedule (or just ignore it if they want to sell us more leads). So, I now have to add this check into our system at the point in which we take in leads, and first check to see if that lead provider (they identify themselves in the XML they send) is allowed to post leads at this particular time.

I honestly don't know where to begin. Has anyone done this before? How did you handle it, and what is good/bad about your method?


This looks like somewhat complex rule-based logic, so the best way in my opinion would be to create a set of objects representing the entities involved. To clarify, I mean to model the rules to objects, applying the most appropriate design patterns applicable.

For example, just out of my head now, if you say that a customer has a set of "rules" when to post, I would model this by having a method on the customer object, something like CanPost(DateTime postTime). That method would check the postTime against the rule collection, what can be as complex as you want them. At first, it can simply be two collections of these first "post-rules" and the ones you later mentioned as "exceptions" in the rules; but this can be really modeled to infinity. Check Martin Fowlers Analysis Patterns for a great reference to many complex domain models, and particularly if you can there is a Accounting Patterns e-book by Fowler, check the PostingRule section

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号