开发者

What data structure for reputation rules in C# (like Stack Overflow)

I am currently building a system which will have entities tha开发者_JAVA百科t will have scores like reputation etc.

I will have a service that will check for certain rules having been triggered, and will perform certain logic if they are triggered.

Previously I have used say an Enum for doing this when I have only had to store an id and a description.

public enum ShoppingCratCalculation
{
    PartialCalculation = 1,
    CompleteCalculation =2
}

But in this situation I want to carry more information, such as the modification to reputation, all in one place.

I'm essentially asking what data structure would be best suited to storing this information, for each rule in the system.

1. Description = string ("User forgot to write a review")
2. DB id = int (23)
3. Rep score modification = int (-5)

Maybe a little class (Rule) with these as properties, and then just a list<Rule>?

Does anyone have any best practice suggestions for this kind of struct?


I'd probably use a class to store the rule data, but the data structure that you use to store them really depends on how your rules are organized. You say it's like SO, but SO usually maps actions onto reputation. From your example, it sounds as if you are mapping qualities of an action onto reputation. In that case, using the same sort of system may not be appropriate. For example, do you really want the possibility of a negative scoring action -- SO does allow this, but perhaps you don't. After all, it sounds like your objective is to sell things -- you might want to consider the impact of giving a person a negative reputation for buying something.

Having said that, here are a few things I'd consider. If the structure is flat and only one rule can apply at any given time or each rule is independent, then a Dictionary keyed by rule identifier (perhaps an enum) might be appropriate. If more than one rule can apply and they interact, then perhaps you might want store them in a collection and build up a compound rule using the Decorator pattern from all the matching rules. For example, purchasing with an authenticated account and writing a review might give you more reputation than writing a review with an anonymous account. If the rules are hierarchical, i.e., there's some precedence, then a filter chain, with the option to abort the chain, might be more appropriate.


You may want to look at some of the production systems. These allow you to process rules and react to actions by performing defined actions.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜