I am building a small application and I am trying to understand the best way to approach the design. I am looking for some guidance/advice how best to approach the following issue.
What I have is that I receive a set of data, real time. I then analyze the data for patterns. The patterns are classes that derive from an abstract class which implements an interface. The number of patterns will change over time as patterns are added/removed. In addition, depending on the access level of the user, the data is analyzed with different pattern options.
For example, if I have five patterns, A, B, C, D and E, level 100 access may only analyze the data with pattern A whereas access level 300 will analyze with patterns B, D and E, and access level 500 will analyze with all the patterns. The access levels are linked to the user, and a user can have different access levels on different data streams.
My thought is to create a hash table or dictionary for the patterns and a db for the users and their various access levels. Is this the best way to go or is there a better approach that will work in real time?
11
You’re on the right track, what you’ve described is a classic Strategy pattern.
There seems to be some confusion around the answer and I’ll elaborate. The question is a little ambiguous as to what is being asked and such broad questions are usually flagged, but I wanted to answer the general gist.
The composition of behaviors over a single interface allows for multiple implementations to be instantiated and swapped out at run-time, which is the basic definition of a strategy pattern. The behaviors can be instantiated upon startup or construction and then stored in a simple dictionary for selection by key on an as-needed basis, or perhaps constructed on the fly as needed via dependency injection.
Several commentators seem to be taking issue with the notion of ‘real time’ as it is traditionally used as speed of results, and my perspective relevant to the question is simply that data is processed per call.
Lastly, a persistent data store of users and roles is exactly what is needed to create an authorization scheme for demarcating which behaviors can be used by which users.
Hopefully this clears up the answer.
4
I coded a similar type of application where I have various access levels and patterns to analize a input data, in that case what my team do was make all the patterns as childs of a abstract class and store that classes name in the database, users and their access level were stored as well. When a user logs to the system all the patters for his level were loaded via reflection. In our case the data was the Twitter Stream and we analize all the tweets to match with predefine patters such “HasALink” or “MentionPeopleInList”, the solution perform well for us.
2